fix up of votes

This commit is contained in:
krawieck 2020-09-18 22:07:48 +02:00
parent e7876af0bc
commit a50501d434
1 changed files with 11 additions and 7 deletions

View File

@ -440,7 +440,7 @@ class _Voting extends HookWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
final myVote = useState(post.myVote ?? 0); final myVote = useState(post.myVote ?? VoteType.none);
final loading = useDelayedLoading(Duration(milliseconds: 500)); final loading = useDelayedLoading(Duration(milliseconds: 500));
final loggedInAction = useLoggedInAction(post.instanceUrl); final loggedInAction = useLoggedInAction(post.instanceUrl);
@ -466,24 +466,28 @@ class _Voting extends HookWidget {
IconButton( IconButton(
icon: Icon( icon: Icon(
Icons.arrow_upward, Icons.arrow_upward,
color: myVote.value == 1 ? theme.accentColor : null, color: myVote.value == VoteType.up ? theme.accentColor : null,
), ),
onPressed: loggedInAction( onPressed: loggedInAction(
(token) => (token) => vote(
vote(myVote.value == 1 ? VoteType.none : VoteType.up, token), myVote.value == VoteType.up ? VoteType.none : VoteType.up,
token,
),
)), )),
if (loading.loading) if (loading.loading)
SizedBox(child: CircularProgressIndicator(), width: 20, height: 20) SizedBox(child: CircularProgressIndicator(), width: 20, height: 20)
else else
Text(NumberFormat.compact().format(post.score + myVote.value)), Text(NumberFormat.compact().format(post.score + myVote.value.value)),
IconButton( IconButton(
icon: Icon( icon: Icon(
Icons.arrow_downward, Icons.arrow_downward,
color: myVote.value == -1 ? Colors.red : null, color: myVote.value == VoteType.down ? Colors.red : null,
), ),
onPressed: loggedInAction( onPressed: loggedInAction(
(token) => vote( (token) => vote(
myVote.value == -1 ? VoteType.none : VoteType.down, token), myVote.value == VoteType.down ? VoteType.none : VoteType.down,
token,
),
)), )),
], ],
); );