From ef7ba71bccf2922df23a84be2f11e9a410a3d436 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Fri, 16 Apr 2021 20:32:20 +0200 Subject: [PATCH] Implement show scores --- lib/widgets/comment.dart | 9 +++++++-- lib/widgets/post.dart | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index cbe5b58..2650fe7 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -93,6 +93,8 @@ class CommentWidget extends HookWidget { final theme = Theme.of(context); final accStore = useAccountsStore(); + final showScores = + useConfigStoreSelect((configStore) => configStore.showScores); final isMine = commentTree.comment.comment.creatorId == accStore.defaultUserDataFor(commentTree.comment.instanceHost)?.userId; @@ -387,10 +389,13 @@ class CommentWidget extends HookWidget { SizedBox.fromSize( size: const Size.square(16), child: const CircularProgressIndicator()) - else + else if (showScores) Text(compactNumber(comment.counts.score + (wasVoted ? 0 : myVote.value.value))), - const Text(' · '), + if (showScores) + const Text(' · ') + else + const SizedBox(width: 4), Text(comment.comment.published.fancy), ], ), diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index daa6f86..d35b7f2 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -9,6 +9,7 @@ import 'package:url_launcher/url_launcher.dart' as ul; import '../hooks/delayed_loading.dart'; import '../hooks/logged_in_action.dart'; +import '../hooks/stores.dart'; import '../l10n/l10n.dart'; import '../pages/full_post.dart'; import '../url_launcher.dart'; @@ -496,6 +497,8 @@ class _Voting extends HookWidget { final theme = Theme.of(context); final myVote = useState(post.myVote ?? VoteType.none); final loading = useDelayedLoading(); + final showScores = + useConfigStoreSelect((configStore) => configStore.showScores); final loggedInAction = useLoggedInAction(post.instanceHost); vote(VoteType vote, Jwt token) async { @@ -518,20 +521,21 @@ class _Voting extends HookWidget { return Row( children: [ IconButton( - icon: Icon( - Icons.arrow_upward, - color: myVote.value == VoteType.up ? theme.accentColor : null, + icon: Icon( + Icons.arrow_upward, + color: myVote.value == VoteType.up ? theme.accentColor : null, + ), + onPressed: loggedInAction( + (token) => vote( + myVote.value == VoteType.up ? VoteType.none : VoteType.up, + token, ), - onPressed: loggedInAction( - (token) => vote( - myVote.value == VoteType.up ? VoteType.none : VoteType.up, - token, - ), - )), + ), + ), if (loading.loading) const SizedBox( width: 20, height: 20, child: CircularProgressIndicator()) - else + else if (showScores) Text(NumberFormat.compact() .format(post.counts.score + (wasVoted ? 0 : myVote.value.value))), IconButton(