Skip to content

Commit

Permalink
Refactor comment chip
Browse files Browse the repository at this point in the history
  • Loading branch information
r52 committed Jun 29, 2024
1 parent 572818e commit da54dd6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
67 changes: 30 additions & 37 deletions lib/mangadex/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class ChapterButtonWidget extends HookWidget {
}

return chips;
}, [chapter, iconSet, screenSizeSmall]);
}, [chapter, iconSet]);

final userChip = IconTextChip(
icon: !isOfficialPub ? iconSet[_IconSet.person] : iconSet[_IconSet.check],
Expand All @@ -431,25 +431,7 @@ class ChapterButtonWidget extends HookWidget {
},
));

return IconTextChip(
icon: const Icon(
Icons.chat_bubble_outline,
size: 18,
),
text: (stats != null && stats.comments != null)
? '${stats.comments?.repliesCount}'
: 'N/A',
onPressed: (stats != null && stats.comments != null)
? () async {
final url =
'https://forums.mangadex.org/threads/${stats.comments!.threadId}';

if (!await launchUrl(Uri.parse(url))) {
throw 'Could not launch $url';
}
}
: null,
);
return CommentChip(comments: stats?.comments);
},
);

Expand Down Expand Up @@ -1218,23 +1200,7 @@ class MangaStatisticsRow extends ConsumerWidget {
const SizedBox(
width: 5,
),
IconTextChip(
icon: const Icon(
Icons.chat_bubble_outline,
size: 18,
),
text: (comments != null) ? '${comments.repliesCount}' : 'N/A',
onPressed: (comments != null)
? () async {
final url =
'https://forums.mangadex.org/threads/${comments.threadId}';

if (!await launchUrl(Uri.parse(url))) {
throw 'Could not launch $url';
}
}
: null,
),
CommentChip(comments: comments),
],
_ => [
const IconTextChip(
Expand All @@ -1253,6 +1219,33 @@ class MangaStatisticsRow extends ConsumerWidget {
}
}

class CommentChip extends StatelessWidget {
final StatisticsDetailsComments? comments;

const CommentChip({super.key, this.comments});

@override
Widget build(BuildContext context) {
return IconTextChip(
icon: const Icon(
Icons.chat_bubble_outline,
size: 18,
),
text: (comments != null) ? '${comments!.repliesCount}' : 'N/A',
onPressed: (comments != null)
? () async {
final url =
'https://forums.mangadex.org/threads/${comments!.threadId}';

if (!await launchUrl(Uri.parse(url))) {
throw 'Could not launch $url';
}
}
: null,
);
}
}

class MangaStatusChip extends StatelessWidget {
const MangaStatusChip({
super.key,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ packages:
dependency: "direct main"
description:
name: flutter_markdown
sha256: "85cc6f7daeae537844c92e2d56e2aff61b00095f8f77913b529ea4be12fc45ea"
sha256: "2e8a801b1ded5ea001a4529c97b1f213dcb11c6b20668e081cafb23468593514"
url: "https://pub.dev"
source: hosted
version: "0.7.2+1"
version: "0.7.3"
flutter_native_splash:
dependency: "direct dev"
description:
Expand Down

0 comments on commit da54dd6

Please sign in to comment.