From 2f5a6112c87856e5c44aac3fe5e6b593be15e542 Mon Sep 17 00:00:00 2001 From: sherlock Date: Wed, 10 Jan 2024 14:41:14 +0700 Subject: [PATCH] hot-fix: cancel send media also show error toast --- lib/pages/chat/send_file_dialog.dart | 9 ++++---- lib/pages/chat/send_file_dialog_view.dart | 5 ++++- .../send_media_with_caption_status_enum.dart | 5 +++++ .../send_files_with_caption_web_mixin.dart | 22 ++++++++++++++----- 4 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 lib/presentation/enum/chat/send_media_with_caption_status_enum.dart diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index f503aec62..092b01ac2 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -3,6 +3,7 @@ import 'package:fluffychat/domain/usecase/send_files_on_web_with_caption_interac import 'package:fluffychat/domain/usecase/send_media_on_web_with_caption_interactor.dart'; import 'package:fluffychat/pages/chat/input_bar/focus_suggestion_controller.dart'; import 'package:fluffychat/pages/chat/send_file_dialog_view.dart'; +import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart'; import 'package:flutter/material.dart'; import 'package:matrix/matrix.dart'; @@ -51,7 +52,7 @@ class SendFileDialogController extends State { void sendMediaWithCaption() { if (widget.room == null) { Logs().e("sendMediaWithCaption:: room is null"); - Navigator.of(context).pop(); + Navigator.of(context).pop(SendMediaWithCaptionStatus.error); return; } sendMediaOnWebWithCaptionInteractor.execute( @@ -59,13 +60,13 @@ class SendFileDialogController extends State { media: widget.files.first, caption: textEditingController.text, ); - Navigator.of(context).pop(true); + Navigator.of(context).pop(SendMediaWithCaptionStatus.done); } void sendFilesWithCaption() { if (widget.room == null) { Logs().e("sendFilesWithCaption:: room is null"); - Navigator.of(context).pop(); + Navigator.of(context).pop(SendMediaWithCaptionStatus.error); return; } sendFilesOnWebWithCaptionInteractor.execute( @@ -73,7 +74,7 @@ class SendFileDialogController extends State { files: widget.files, caption: textEditingController.text, ); - Navigator.of(context).pop(true); + Navigator.of(context).pop(SendMediaWithCaptionStatus.done); } void send() { diff --git a/lib/pages/chat/send_file_dialog_view.dart b/lib/pages/chat/send_file_dialog_view.dart index a2a2b01e2..7d93ba6e5 100644 --- a/lib/pages/chat/send_file_dialog_view.dart +++ b/lib/pages/chat/send_file_dialog_view.dart @@ -1,6 +1,7 @@ import 'package:fluffychat/pages/chat/input_bar/input_bar.dart'; import 'package:fluffychat/pages/chat/send_file_dialog.dart'; import 'package:fluffychat/pages/image_viewer/image_viewer.dart'; +import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart'; import 'package:fluffychat/presentation/extensions/send_file_web_extension.dart'; import 'package:fluffychat/utils/interactive_viewer_gallery.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; @@ -73,7 +74,9 @@ class SendFileDialogView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.end, children: [ TextButton( - onPressed: () => Navigator.of(context).pop(), + onPressed: () => Navigator.of(context).pop( + SendMediaWithCaptionStatus.cancel, + ), style: ButtonStyle( shape: MaterialStatePropertyAll( RoundedRectangleBorder( diff --git a/lib/presentation/enum/chat/send_media_with_caption_status_enum.dart b/lib/presentation/enum/chat/send_media_with_caption_status_enum.dart new file mode 100644 index 000000000..c492c3c70 --- /dev/null +++ b/lib/presentation/enum/chat/send_media_with_caption_status_enum.dart @@ -0,0 +1,5 @@ +enum SendMediaWithCaptionStatus { + cancel, + done, + error, +} diff --git a/lib/presentation/mixins/send_files_with_caption_web_mixin.dart b/lib/presentation/mixins/send_files_with_caption_web_mixin.dart index 5770731c6..74bd94173 100644 --- a/lib/presentation/mixins/send_files_with_caption_web_mixin.dart +++ b/lib/presentation/mixins/send_files_with_caption_web_mixin.dart @@ -1,5 +1,6 @@ import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/chat/send_file_dialog.dart'; +import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:fluffychat/utils/platform_infos.dart'; @@ -14,7 +15,7 @@ mixin SendFilesWithCaptionWebMixin { }) async { if (matrixFilesList.length <= AppConfig.maxFilesSendPerDialog && matrixFilesList.isNotEmpty) { - showDialog( + final result = await showDialog( context: context, useRootNavigator: PlatformInfos.isWeb, builder: (context) { @@ -24,17 +25,26 @@ mixin SendFilesWithCaptionWebMixin { ); }, ); + if (result is SendMediaWithCaptionStatus) { + switch (result) { + case SendMediaWithCaptionStatus.done: + break; + case SendMediaWithCaptionStatus.error: + TwakeSnackBar.show( + context, + L10n.of(context)!.failedToSendFiles, + ); + break; + case SendMediaWithCaptionStatus.cancel: + break; + } + } } else if (matrixFilesList.length > AppConfig.maxFilesSendPerDialog) { TwakeSnackBar.show( context, L10n.of(context)! .countFilesSendPerDialog(AppConfig.maxFilesSendPerDialog), ); - } else { - TwakeSnackBar.show( - context, - L10n.of(context)!.failedToSendFiles, - ); } } }