fix bug where scores would show as 1 too many or 1 too few
This commit is contained in:
parent
d0913ca3fa
commit
82d153533a
|
@ -23,6 +23,8 @@ class Comment extends HookWidget {
|
|||
final int postCreatorId;
|
||||
final CommentTree commentTree;
|
||||
|
||||
final bool wasVoted;
|
||||
|
||||
static const colors = [
|
||||
Colors.pink,
|
||||
Colors.green,
|
||||
|
@ -35,7 +37,8 @@ class Comment extends HookWidget {
|
|||
this.commentTree, {
|
||||
this.indent = 0,
|
||||
@required this.postCreatorId,
|
||||
});
|
||||
}) : wasVoted =
|
||||
(commentTree.comment.myVote ?? VoteType.none) != VoteType.none;
|
||||
|
||||
_showCommentInfo(BuildContext context) {
|
||||
final com = commentTree.comment;
|
||||
|
@ -343,8 +346,8 @@ class Comment extends HookWidget {
|
|||
size: Size.square(16),
|
||||
child: CircularProgressIndicator())
|
||||
else
|
||||
Text(compactNumber(
|
||||
comment.score + myVote.value.value)),
|
||||
Text(compactNumber(comment.score +
|
||||
(wasVoted ? 0 : myVote.value.value))),
|
||||
Text(' · '),
|
||||
Text(timeago.format(comment.published)),
|
||||
],
|
||||
|
|
|
@ -435,7 +435,10 @@ class Post extends HookWidget {
|
|||
class _Voting extends HookWidget {
|
||||
final PostView post;
|
||||
|
||||
_Voting(this.post);
|
||||
final bool wasVoted;
|
||||
|
||||
_Voting(this.post)
|
||||
: wasVoted = (post.myVote ?? VoteType.none) != VoteType.none;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -477,7 +480,8 @@ class _Voting extends HookWidget {
|
|||
if (loading.loading)
|
||||
SizedBox(child: CircularProgressIndicator(), width: 20, height: 20)
|
||||
else
|
||||
Text(NumberFormat.compact().format(post.score + myVote.value.value)),
|
||||
Text(NumberFormat.compact()
|
||||
.format(post.score + (wasVoted ? 0 : myVote.value.value))),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_downward,
|
||||
|
|
Loading…
Reference in New Issue