Skip to content

Commit 118311e

Browse files
committed
wip; Add server validation
Might need to extract a separate stateful widget.
1 parent 0c6ee2e commit 118311e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/widgets/compose_box.dart

+19-6
Original file line numberDiff line numberDiff line change
@@ -1429,12 +1429,25 @@ class _SavedSnippetComposeBoxBody extends _ComposeBoxBody {
14291429
return Align(
14301430
alignment: Alignment.centerRight,
14311431
child: IconButton(
1432-
onPressed: () {
1433-
Navigator.pop(context);
1434-
// TODO handle validation errors; server errors
1435-
createSavedSnippet(store.connection,
1436-
title: controller.title.textNormalized,
1437-
content: controller.content.textNormalized);
1432+
onPressed: () async {
1433+
// TODO client-side validations
1434+
try {
1435+
await createSavedSnippet(store.connection,
1436+
title: controller.title.textNormalized,
1437+
content: controller.content.textNormalized);
1438+
if (!context.mounted) return;
1439+
Navigator.pop(context);
1440+
} on ApiRequestException catch (e) {
1441+
if (!context.mounted) return;
1442+
final zulipLocalizations = ZulipLocalizations.of(context);
1443+
final message = switch (e) {
1444+
ZulipApiException() => zulipLocalizations.errorServerMessage(e.message),
1445+
_ => e.message,
1446+
};
1447+
showErrorDialog(context: context,
1448+
title: zulipLocalizations.errorFailedToCreateSavedSnippet,
1449+
message: message);
1450+
}
14381451
}, icon: Icon(ZulipIcons.check, color: designVariables.icon)));
14391452
}
14401453
}

0 commit comments

Comments
 (0)