moved out logic from UI

This commit is contained in:
shilangyu 2020-09-08 16:41:46 +02:00
parent 8eb31434e2
commit 94daf2acc6
1 changed files with 35 additions and 33 deletions

View File

@ -165,6 +165,22 @@ class _AccountsConfigAddInstanceDialog extends HookWidget {
var loading = useState(false);
handleOnAdd() async {
try {
loading.value = true;
await context
.read<AccountsStore>()
.addInstance(instanceController.text);
scaffoldKey.currentState.hideCurrentSnackBar();
} on Exception catch (err) {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
}
loading.value = false;
Navigator.of(context).pop();
}
return AlertDialog(
title: Text('Add instance'),
content: TextField(
@ -182,23 +198,7 @@ class _AccountsConfigAddInstanceDialog extends HookWidget {
),
FlatButton(
child: !loading.value ? Text('Add') : CircularProgressIndicator(),
onPressed: instanceController.text.isEmpty
? null
: () async {
try {
loading.value = true;
await context
.read<AccountsStore>()
.addInstance(instanceController.text);
scaffoldKey.currentState.hideCurrentSnackBar();
} on Exception catch (err) {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
}
loading.value = false;
Navigator.of(context).pop();
},
onPressed: instanceController.text.isEmpty ? null : handleOnAdd,
),
],
);
@ -223,6 +223,23 @@ class _AccountsConfigAddAccountDialog extends HookWidget {
var loading = useState(false);
handleOnAdd() async {
try {
loading.value = true;
await context.read<AccountsStore>().addAccount(
instanceUrl,
usernameController.text,
passwordController.text,
);
} on Exception catch (err) {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
}
loading.value = false;
Navigator.of(context).pop();
}
return AlertDialog(
title: Text('Add account'),
content: Column(
@ -257,22 +274,7 @@ class _AccountsConfigAddAccountDialog extends HookWidget {
onPressed:
usernameController.text.isEmpty || passwordController.text.isEmpty
? null
: () async {
try {
loading.value = true;
await context.read<AccountsStore>().addAccount(
instanceUrl,
usernameController.text,
passwordController.text,
);
} on Exception catch (err) {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
}
loading.value = false;
Navigator.of(context).pop();
},
: handleOnAdd,
),
],
);