2021-09-11 01:04:15 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:lemmy_api_client/v3.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../../hooks/logged_in_action.dart';
|
|
|
|
import '../../hooks/stores.dart';
|
|
|
|
import '../../util/intl.dart';
|
|
|
|
import '../../util/observer_consumers.dart';
|
|
|
|
import 'post_store.dart';
|
|
|
|
|
|
|
|
class PostVoting extends HookWidget {
|
|
|
|
const PostVoting();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
final showScores =
|
|
|
|
useConfigStoreSelect((configStore) => configStore.showScores);
|
|
|
|
final loggedInAction = useLoggedInAction(context
|
|
|
|
.select<PostStore, String>((store) => store.postView.instanceHost));
|
|
|
|
|
|
|
|
return ObserverBuilder<PostStore>(builder: (context, store) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.arrow_upward,
|
|
|
|
color: store.postView.myVote == VoteType.up
|
|
|
|
? theme.colorScheme.secondary
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
onPressed: loggedInAction(store.upVote),
|
|
|
|
),
|
2021-09-11 01:27:21 +02:00
|
|
|
if (store.votingState.isLoading)
|
2021-09-11 01:04:15 +02:00
|
|
|
const SizedBox(
|
2021-10-19 01:30:30 +02:00
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
)
|
2021-09-11 01:04:15 +02:00
|
|
|
else if (showScores)
|
2021-10-19 01:30:30 +02:00
|
|
|
Text(compactNumber(store.postView.counts.score)),
|
2021-09-11 01:04:15 +02:00
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.arrow_downward,
|
|
|
|
color: store.postView.myVote == VoteType.down ? Colors.red : null,
|
|
|
|
),
|
|
|
|
onPressed: loggedInAction(store.downVote),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|