cleanup some TODOs
This commit is contained in:
parent
0540be3ede
commit
08af8e5997
|
@ -28,8 +28,7 @@ class CommunitiesTab extends HookWidget {
|
|||
});
|
||||
final isCollapsed = useState(List.filled(amountOfDisplayInstances, false));
|
||||
|
||||
// TODO: use useMemoFuture
|
||||
final instancesFut = useMemoized(() {
|
||||
final instancesSnap = useMemoFuture(() {
|
||||
final futures = accountsStore.users.keys
|
||||
.where((e) => !accountsStore.isAnonymousFor(e))
|
||||
.map(
|
||||
|
@ -40,7 +39,7 @@ class CommunitiesTab extends HookWidget {
|
|||
|
||||
return Future.wait(futures);
|
||||
});
|
||||
final communitiesFut = useMemoized(() {
|
||||
final communitiesSnap = useMemoFuture(() {
|
||||
final futures = accountsStore.users.keys
|
||||
.where((e) => !accountsStore.isAnonymousFor(e))
|
||||
.map(
|
||||
|
@ -58,9 +57,6 @@ class CommunitiesTab extends HookWidget {
|
|||
return Future.wait(futures);
|
||||
});
|
||||
|
||||
final communitiesSnap = useFuture(communitiesFut);
|
||||
final instancesSnap = useFuture(instancesFut);
|
||||
|
||||
if (communitiesSnap.hasError || instancesSnap.hasError) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
|
|
|
@ -538,9 +538,7 @@ class _FollowButton extends HookWidget {
|
|||
|
||||
final token = useAccountsStore().defaultTokenFor(community.instanceUrl);
|
||||
|
||||
// TODO: use hook for handling spinner and pending
|
||||
final showSpinner = useState(false);
|
||||
final isPending = useState(false);
|
||||
final delayed = useDelayedLoading(const Duration(milliseconds: 500));
|
||||
|
||||
final colorOnTopOfAccent = textColorBasedOnBackground(theme.accentColor);
|
||||
|
||||
|
@ -551,13 +549,10 @@ class _FollowButton extends HookWidget {
|
|||
return;
|
||||
}
|
||||
|
||||
isPending.value = true;
|
||||
final spinnerTimer =
|
||||
Timer(Duration(milliseconds: 500), () => showSpinner.value = true);
|
||||
delayed.start();
|
||||
|
||||
final api = LemmyApi(community.instanceUrl).v1;
|
||||
try {
|
||||
await api.followCommunity(
|
||||
await LemmyApi(community.instanceUrl).v1.followCommunity(
|
||||
communityId: community.id,
|
||||
follow: !isSubbed.value,
|
||||
auth: token?.raw);
|
||||
|
@ -575,17 +570,14 @@ class _FollowButton extends HookWidget {
|
|||
));
|
||||
}
|
||||
|
||||
// clean up
|
||||
spinnerTimer.cancel();
|
||||
isPending.value = false;
|
||||
showSpinner.value = false;
|
||||
delayed.cancel();
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
height: 27,
|
||||
width: 160,
|
||||
child: showSpinner.value
|
||||
child: delayed.loading
|
||||
? RaisedButton(
|
||||
onPressed: null,
|
||||
child: SizedBox(
|
||||
|
@ -599,7 +591,7 @@ class _FollowButton extends HookWidget {
|
|||
)
|
||||
: RaisedButton.icon(
|
||||
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
||||
onPressed: isPending.value ? () {} : subscribe,
|
||||
onPressed: delayed.pending ? () {} : subscribe,
|
||||
icon: isSubbed.value
|
||||
? Icon(Icons.remove, size: 18, color: colorOnTopOfAccent)
|
||||
: Icon(Icons.add, size: 18, color: colorOnTopOfAccent),
|
||||
|
|
|
@ -14,7 +14,6 @@ abstract class _AccountsStore with Store {
|
|||
_AccountsStore() {
|
||||
// persistently save settings each time they are changed
|
||||
_saveReactionDisposer = reaction(
|
||||
// TODO: does not react to deep changes in users and tokens
|
||||
(_) => [
|
||||
users.forEach((k, submap) =>
|
||||
MapEntry(k, submap.forEach((k2, v2) => MapEntry(k2, v2)))),
|
||||
|
|
Loading…
Reference in New Issue