Implement show scores

This commit is contained in:
shilangyu 2021-04-16 20:32:20 +02:00
parent 7138f9b76c
commit ef7ba71bcc
2 changed files with 21 additions and 12 deletions

View File

@ -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),
],
),

View File

@ -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(