From ea58a4bd1644dc100b55a22963a40eb224a6726c Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 5 Mar 2024 23:13:39 +0700 Subject: [PATCH] TF-2667 Replace `isSendEmailLoading` to `ButtonState` --- .../presentation/composer_controller.dart | 38 ++++++++----------- .../composer/presentation/composer_view.dart | 6 +-- .../presentation/composer_view_web.dart | 5 +-- .../web/bottom_bar_composer_widget.dart | 5 +-- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index dfc8b0b0e..3c404c95d 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -116,7 +116,6 @@ class ComposerController extends BaseController with DragDropFileMixin { final fromRecipientState = PrefixRecipientState.disabled.obs; final ccRecipientState = PrefixRecipientState.disabled.obs; final bccRecipientState = PrefixRecipientState.disabled.obs; - final isSendEmailLoading = false.obs; final identitySelected = Rxn(); final listFromIdentities = RxList(); @@ -182,6 +181,7 @@ class ComposerController extends BaseController with DragDropFileMixin { bool isAttachmentCollapsed = false; ButtonState _closeComposerButtonState = ButtonState.enabled; ButtonState _saveToDraftButtonState = ButtonState.enabled; + ButtonState _sendButtonState = ButtonState.enabled; late Worker uploadInlineImageWorker; late Worker dashboardViewStateWorker; @@ -309,9 +309,6 @@ class ComposerController extends BaseController with DragDropFileMixin { } else if (failure is GetEmailContentFailure || failure is TransformHtmlEmailContentFailure) { emailContentsViewState.value = Left(failure); - if (isSendEmailLoading.isTrue) { - isSendEmailLoading.value = false; - } } else if (failure is GetAllIdentitiesFailure) { if (identitySelected.value == null) { _autoFocusFieldWhenLauncher(); @@ -805,15 +802,15 @@ class ComposerController extends BaseController with DragDropFileMixin { } } - void validateInformationBeforeSending(BuildContext context) async { - if (isSendEmailLoading.isTrue) { + void handleClickSendButton(BuildContext context) async { + if (_sendButtonState == ButtonState.disabled) { + log('ComposerController::handleClickSendButton: SENDING EMAIL'); return; } + _sendButtonState = ButtonState.disabled; clearFocus(context); - isSendEmailLoading.value = true; - if (toEmailAddressController.text.isNotEmpty || ccEmailAddressController.text.isNotEmpty || bccEmailAddressController.text.isNotEmpty) { @@ -825,12 +822,11 @@ class ComposerController extends BaseController with DragDropFileMixin { showConfirmDialogAction(context, AppLocalizations.of(context).message_dialog_send_email_without_recipient, AppLocalizations.of(context).add_recipients, - onConfirmAction: () => isSendEmailLoading.value = false, title: AppLocalizations.of(context).sending_failed, icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill), hasCancelButton: false, showAsBottomSheet: true, - ).whenComplete(() => isSendEmailLoading.value = false); + ).whenComplete(() => _sendButtonState = ButtonState.enabled); return; } @@ -846,13 +842,12 @@ class ComposerController extends BaseController with DragDropFileMixin { toAddressExpandMode.value = ExpandMode.EXPAND; ccAddressExpandMode.value = ExpandMode.EXPAND; bccAddressExpandMode.value = ExpandMode.EXPAND; - isSendEmailLoading.value = false; }, showAsBottomSheet: true, title: AppLocalizations.of(context).sending_failed, icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill), hasCancelButton: false - ).whenComplete(() => isSendEmailLoading.value = false); + ).whenComplete(() => _sendButtonState = ButtonState.enabled); return; } @@ -860,12 +855,11 @@ class ComposerController extends BaseController with DragDropFileMixin { showConfirmDialogAction(context, AppLocalizations.of(context).message_dialog_send_email_without_a_subject, AppLocalizations.of(context).send_anyway, - onConfirmAction: () => _handleSendMessages(context), - onCancelAction: () => isSendEmailLoading.value = false, + onConfirmAction: _handleSendMessages, title: AppLocalizations.of(context).empty_subject, showAsBottomSheet: true, icon: SvgPicture.asset(imagePaths.icEmpty, fit: BoxFit.fill), - ).whenComplete(() => isSendEmailLoading.value = false); + ).whenComplete(() => _sendButtonState = ButtonState.enabled); return; } @@ -874,12 +868,11 @@ class ComposerController extends BaseController with DragDropFileMixin { context, AppLocalizations.of(context).messageDialogSendEmailUploadingAttachment, AppLocalizations.of(context).got_it, - onConfirmAction: () => isSendEmailLoading.value = false, title: AppLocalizations.of(context).sending_failed, showAsBottomSheet: true, icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill), hasCancelButton: false - ).whenComplete(() => isSendEmailLoading.value = false); + ).whenComplete(() => _sendButtonState = ButtonState.enabled); return; } @@ -889,15 +882,14 @@ class ComposerController extends BaseController with DragDropFileMixin { AppLocalizations.of(context).message_dialog_send_email_exceeds_maximum_size( filesize(mailboxDashBoardController.maxSizeAttachmentsPerEmail?.value ?? 0, 0)), AppLocalizations.of(context).got_it, - onConfirmAction: () => isSendEmailLoading.value = false, title: AppLocalizations.of(context).sending_failed, icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill), hasCancelButton: false - ).whenComplete(() => isSendEmailLoading.value = false); + ).whenComplete(() => _sendButtonState = ButtonState.enabled); return; } - _handleSendMessages(context); + _handleSendMessages(); } Future _getContentInEditor() async { @@ -911,12 +903,13 @@ class ComposerController extends BaseController with DragDropFileMixin { } } - void _handleSendMessages(BuildContext context) async { + void _handleSendMessages() async { if (composerArguments.value == null || mailboxDashBoardController.sessionCurrent == null || mailboxDashBoardController.accountId.value == null ) { log('ComposerController::_handleSendMessages: SESSION or ACCOUNT_ID or ARGUMENTS is NULL'); + _sendButtonState = ButtonState.enabled; _closeComposerAction(); return; } @@ -957,6 +950,7 @@ class ComposerController extends BaseController with DragDropFileMixin { barrierColor: AppColor.colorDefaultCupertinoActionSheet, ); + _sendButtonState = ButtonState.enabled; _closeComposerAction(result: resultState); } @@ -1368,8 +1362,6 @@ class ComposerController extends BaseController with DragDropFileMixin { } void _closeComposerAction({dynamic result}) { - isSendEmailLoading.value = false; - if (PlatformInfo.isWeb) { mailboxDashBoardController.closeComposerOverlay(result: result); } else { diff --git a/lib/features/composer/presentation/composer_view.dart b/lib/features/composer/presentation/composer_view.dart index bdb3d6339..e9c707c18 100644 --- a/lib/features/composer/presentation/composer_view.dart +++ b/lib/features/composer/presentation/composer_view.dart @@ -60,7 +60,7 @@ class ComposerView extends GetWidget { Obx(() => LandscapeAppBarComposerWidget( isSendButtonEnabled: controller.isEnableEmailSendButton.value, onCloseViewAction: () => controller.handleClickCloseComposer(context), - sendMessageAction: () => controller.validateInformationBeforeSending(context), + sendMessageAction: () => controller.handleClickSendButton(context), openContextMenuAction: (position) { controller.openPopupMenuAction( context, @@ -74,7 +74,7 @@ class ComposerView extends GetWidget { Obx(() => AppBarComposerWidget( isSendButtonEnabled: controller.isEnableEmailSendButton.value, onCloseViewAction: () => controller.handleClickCloseComposer(context), - sendMessageAction: () => controller.validateInformationBeforeSending(context), + sendMessageAction: () => controller.handleClickSendButton(context), openContextMenuAction: (position) { controller.openPopupMenuAction( context, @@ -362,7 +362,7 @@ class ComposerView extends GetWidget { TabletBottomBarComposerWidget( deleteComposerAction: () => controller.handleClickDeleteComposer(context), saveToDraftAction: () => controller.saveToDraftAction(context), - sendMessageAction: () => controller.validateInformationBeforeSending(context), + sendMessageAction: () => controller.handleClickSendButton(context), requestReadReceiptAction: (position) { controller.openPopupMenuAction( context, diff --git a/lib/features/composer/presentation/composer_view_web.dart b/lib/features/composer/presentation/composer_view_web.dart index ccae48433..d1b10e522 100644 --- a/lib/features/composer/presentation/composer_view_web.dart +++ b/lib/features/composer/presentation/composer_view_web.dart @@ -50,7 +50,7 @@ class ComposerView extends GetWidget { onCloseViewAction: () => controller.handleClickCloseComposer(context), attachFileAction: () => controller.openFilePickerByType(context, FileType.any), insertImageAction: () => controller.insertImage(context, constraints.maxWidth), - sendMessageAction: () => controller.validateInformationBeforeSending(context), + sendMessageAction: () => controller.handleClickSendButton(context), openContextMenuAction: (position) { controller.openPopupMenuAction( context, @@ -465,7 +465,6 @@ class ComposerView extends GetWidget { radius: ComposerStyle.popupMenuRadius ); }, - isSending: controller.isSendEmailLoading.value, )), ], ), @@ -756,7 +755,7 @@ class ComposerView extends GetWidget { showCodeViewAction: controller.richTextWebController.toggleCodeView, deleteComposerAction: () => controller.handleClickDeleteComposer(context), saveToDraftAction: () => controller.saveToDraftAction(context), - sendMessageAction: () => controller.validateInformationBeforeSending(context), + sendMessageAction: () => controller.handleClickSendButton(context), requestReadReceiptAction: (position) { controller.openPopupMenuAction( context, diff --git a/lib/features/composer/presentation/widgets/web/bottom_bar_composer_widget.dart b/lib/features/composer/presentation/widgets/web/bottom_bar_composer_widget.dart index 648ac8630..691f7136d 100644 --- a/lib/features/composer/presentation/widgets/web/bottom_bar_composer_widget.dart +++ b/lib/features/composer/presentation/widgets/web/bottom_bar_composer_widget.dart @@ -19,7 +19,6 @@ class BottomBarComposerWidget extends StatelessWidget { final VoidCallback saveToDraftAction; final VoidCallback sendMessageAction; final OnRequestReadReceiptAction? requestReadReceiptAction; - final bool isSending; final _imagePaths = Get.find(); @@ -35,7 +34,6 @@ class BottomBarComposerWidget extends StatelessWidget { required this.saveToDraftAction, required this.sendMessageAction, this.requestReadReceiptAction, - this.isSending = false, }); @override @@ -129,7 +127,7 @@ class BottomBarComposerWidget extends StatelessWidget { ), const SizedBox(width: BottomBarComposerWidgetStyle.sendButtonSpace), TMailButtonWidget( - text: isSending ? AppLocalizations.of(context).sending : AppLocalizations.of(context).send, + text: AppLocalizations.of(context).send, icon: _imagePaths.icSend, iconAlignment: TextDirection.rtl, padding: BottomBarComposerWidgetStyle.sendButtonPadding, @@ -139,7 +137,6 @@ class BottomBarComposerWidget extends StatelessWidget { backgroundColor: BottomBarComposerWidgetStyle.sendButtonBackgroundColor, borderRadius: BottomBarComposerWidgetStyle.sendButtonRadius, onTapActionCallback: sendMessageAction, - isLoading: isSending, ) ] ),