From 6f6284c21f445873224c65bda5bd48c136f39ef4 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 19 Nov 2025 12:02:13 +0700 Subject: [PATCH] fix: missing To field when only other fields are filled --- .../presentation/composer_controller.dart | 15 ++--- .../composer/presentation/composer_view.dart | 2 +- .../presentation/composer_view_web.dart | 2 +- ...andle_recipients_collapsed_extensions.dart | 55 ++++++++++++++++++- .../widgets/recipient_composer_widget.dart | 21 ++++++- 5 files changed, 79 insertions(+), 16 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 8d9aa4a99..3592ba1c5 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -591,7 +591,7 @@ class ComposerController extends BaseController richTextMobileTabletController?.richTextController.hideRichTextView(); } autoCreateEmailTag(); - triggerHideRecipientsFiledsWhenUnfocus(); + triggerHideRecipientsFieldsWhenUnfocus(); } } @@ -1440,7 +1440,7 @@ class ComposerController extends BaseController void clickOutsideComposer() { clearFocus(); - triggerHideRecipientsFiledsWhenUnfocus(); + triggerHideRecipientsFieldsWhenUnfocus(); if (PlatformInfo.isWeb) { refocusKeyboardShortcutFocus(); } @@ -1718,7 +1718,7 @@ class ComposerController extends BaseController richTextMobileTabletController?.richTextController.showDeviceKeyboard); } autoCreateEmailTag(); - triggerHideRecipientsFiledsWhenUnfocus(); + triggerHideRecipientsFieldsWhenUnfocus(); } void _onChangeCursorOnMobile(List? coordinates, BuildContext context) { @@ -1850,7 +1850,7 @@ class ComposerController extends BaseController popBack(); } autoCreateEmailTag(); - triggerHideRecipientsFiledsWhenUnfocus(); + triggerHideRecipientsFieldsWhenUnfocus(); } FocusNode? getNextFocusOfToEmailAddress() { @@ -2302,13 +2302,6 @@ class ComposerController extends BaseController ); } - void handleEnableRecipientsInputAction(bool isEnabled) { - fromRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled; - ccRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled; - bccRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled; - replyToRecipientState.value = isEnabled ? PrefixRecipientState.disabled : PrefixRecipientState.enabled; - } - @override Future onBeforeReconnect() async { if (mailboxDashBoardController.accountId.value != null && diff --git a/lib/features/composer/presentation/composer_view.dart b/lib/features/composer/presentation/composer_view.dart index fb14b5b0d..159722820 100644 --- a/lib/features/composer/presentation/composer_view.dart +++ b/lib/features/composer/presentation/composer_view.dart @@ -527,7 +527,7 @@ class ComposerView extends GetWidget { onClearFocusAction: controller.onClearFocusAction, onAddEmailAddressTypeAction: controller.addEmailAddressType, onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType, - onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputAction, + onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputOnMobileAction, )); } } \ No newline at end of file diff --git a/lib/features/composer/presentation/composer_view_web.dart b/lib/features/composer/presentation/composer_view_web.dart index 628a4ef83..7277ccda1 100644 --- a/lib/features/composer/presentation/composer_view_web.dart +++ b/lib/features/composer/presentation/composer_view_web.dart @@ -941,7 +941,7 @@ class ComposerView extends GetWidget { onClearFocusAction: controller.onClearFocusAction, onAddEmailAddressTypeAction: controller.addEmailAddressType, onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType, - onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputAction, + onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputOnMobileAction, )); } } \ No newline at end of file diff --git a/lib/features/composer/presentation/extensions/handle_recipients_collapsed_extensions.dart b/lib/features/composer/presentation/extensions/handle_recipients_collapsed_extensions.dart index 45f5aed6b..65aa30484 100644 --- a/lib/features/composer/presentation/extensions/handle_recipients_collapsed_extensions.dart +++ b/lib/features/composer/presentation/extensions/handle_recipients_collapsed_extensions.dart @@ -4,6 +4,7 @@ import 'package:model/extensions/email_address_extension.dart'; import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart'; import 'package:tmail_ui_user/features/composer/presentation/model/prefix_recipient_state.dart'; import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart'; +import 'package:tmail_ui_user/main/routes/route_navigation.dart'; extension HandleRecipientsCollapsedExtensions on ComposerController { List get allListEmailAddress => @@ -52,10 +53,22 @@ extension HandleRecipientsCollapsedExtensions on ComposerController { replyToRecipientState.value = PrefixRecipientState.enabled; } + if (currentContext != null && + responsiveUtils.isMobile(currentContext!) && + isAllRecipientInputEnabled) { + fromRecipientState.value = PrefixRecipientState.enabled; + } + updatePrefixRootState(); requestFocusRecipientInput(); } + bool get isAllRecipientInputEnabled => + toRecipientState.value == PrefixRecipientState.enabled && + ccRecipientState.value == PrefixRecipientState.enabled && + bccRecipientState.value == PrefixRecipientState.enabled && + replyToRecipientState.value == PrefixRecipientState.enabled; + void updatePrefixRootState() { if (toRecipientState.value == PrefixRecipientState.enabled) { prefixRootState.value = PrefixEmailAddress.to; @@ -98,7 +111,7 @@ extension HandleRecipientsCollapsedExtensions on ComposerController { } } - void triggerHideRecipientsFiledsWhenUnfocus() { + void triggerHideRecipientsFieldsWhenUnfocus() { if (isRecipientsEmptyExceptReplyTo) { hideAllRecipientsFieldsExceptTo(); } else if (isRecipientsWithoutReplyToNotEmpty) { @@ -123,4 +136,44 @@ extension HandleRecipientsCollapsedExtensions on ComposerController { replyToRecipientState.value = PrefixRecipientState.disabled; recipientsCollapsedState.value = PrefixRecipientState.disabled; } + + void handleEnableRecipientsInputOnMobileAction(bool isEnabled) { + PrefixRecipientState from; + PrefixRecipientState to; + PrefixRecipientState cc; + PrefixRecipientState bcc; + PrefixRecipientState replyTo; + + if (!isEnabled) { + from = PrefixRecipientState.enabled; + to = PrefixRecipientState.enabled; + cc = PrefixRecipientState.enabled; + bcc = PrefixRecipientState.enabled; + replyTo = PrefixRecipientState.enabled; + } else if (listCcEmailAddress.isNotEmpty) { + from = PrefixRecipientState.disabled; + to = PrefixRecipientState.disabled; + cc = PrefixRecipientState.enabled; + bcc = PrefixRecipientState.disabled; + replyTo = PrefixRecipientState.disabled; + } else if (listBccEmailAddress.isNotEmpty) { + from = PrefixRecipientState.disabled; + to = PrefixRecipientState.disabled; + cc = PrefixRecipientState.disabled; + bcc = PrefixRecipientState.enabled; + replyTo = PrefixRecipientState.disabled; + } else { + from = PrefixRecipientState.disabled; + to = PrefixRecipientState.enabled; + cc = PrefixRecipientState.disabled; + bcc = PrefixRecipientState.disabled; + replyTo = PrefixRecipientState.disabled; + } + + fromRecipientState.value = from; + toRecipientState.value = to; + ccRecipientState.value = cc; + bccRecipientState.value = bcc; + replyToRecipientState.value = replyTo; + } } diff --git a/lib/features/composer/presentation/widgets/recipient_composer_widget.dart b/lib/features/composer/presentation/widgets/recipient_composer_widget.dart index 1da4527f4..0d6cb7622 100644 --- a/lib/features/composer/presentation/widgets/recipient_composer_widget.dart +++ b/lib/features/composer/presentation/widgets/recipient_composer_widget.dart @@ -325,8 +325,7 @@ class _RecipientComposerWidgetState extends State { ), if (widget.prefix == widget.prefixRootState && _isWeb && !isMobileResponsive) ..._buildListPrefixWidgets(), - if (widget.prefix == widget.prefixRootState && (isMobileResponsive || widget.isTestingForWeb)) - _buildExpandButton(), + if (_isShowExpandButton(isMobileResponsive)) _buildExpandButton(), if (widget.prefix != widget.prefixRootState && _isWeb && !isMobileResponsive) TMailButtonWidget.fromIcon( icon: widget.imagePaths.icClose, @@ -400,6 +399,24 @@ class _RecipientComposerWidgetState extends State { ]; } + bool _isShowExpandButton(bool isMobileResponsive) { + final onlyCcEnabled = widget.toState == PrefixRecipientState.disabled && + widget.ccState == PrefixRecipientState.enabled; + + final onlyBccEnabled = widget.toState == PrefixRecipientState.disabled && + widget.ccState == PrefixRecipientState.disabled && + widget.bccState == PrefixRecipientState.enabled; + + final shouldCheckPrefix = switch (widget.prefix) { + PrefixEmailAddress.to => widget.toState == PrefixRecipientState.enabled, + PrefixEmailAddress.cc => onlyCcEnabled, + PrefixEmailAddress.bcc => onlyBccEnabled, + _ => false, + }; + + return shouldCheckPrefix && (isMobileResponsive || widget.isTestingForWeb); + } + Widget _buildExpandButton() { return TMailButtonWidget.fromIcon( key: Key('prefix_${widget.prefix.name}_recipient_expand_button'),