2020-09-18 15:48:37 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
|
|
|
|
|
|
|
import '../pages/settings.dart';
|
|
|
|
import '../util/goto.dart';
|
|
|
|
import 'stores.dart';
|
|
|
|
|
2020-09-18 17:30:32 +02:00
|
|
|
Function(
|
|
|
|
Function(Jwt token) action, [
|
2020-09-18 15:48:37 +02:00
|
|
|
String message,
|
2020-09-18 17:30:32 +02:00
|
|
|
]) useLoggedInAction(
|
|
|
|
String instanceUrl,
|
|
|
|
) {
|
2020-09-18 15:48:37 +02:00
|
|
|
final context = useContext();
|
|
|
|
final store = useAccountsStore();
|
|
|
|
|
2020-09-18 17:30:32 +02:00
|
|
|
return (Function(Jwt token) action, [message]) {
|
2020-09-18 15:48:37 +02:00
|
|
|
if (store.isAnonymousFor(instanceUrl)) {
|
|
|
|
return () {
|
|
|
|
Scaffold.of(context).showSnackBar(SnackBar(
|
2020-09-18 21:24:33 +02:00
|
|
|
content: Text(message ?? 'you have to be logged in to do that'),
|
2020-09-18 15:48:37 +02:00
|
|
|
action: SnackBarAction(
|
|
|
|
label: 'log in',
|
|
|
|
onPressed: () => goTo(context, (_) => AccountsConfigPage())),
|
|
|
|
));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
final token = store.defaultTokenFor(instanceUrl);
|
|
|
|
return () => action(token);
|
|
|
|
};
|
|
|
|
}
|