fix: missing To field when only other fields are filled

This commit is contained in:
dab246
2025-11-19 12:02:13 +07:00
committed by Dat H. Pham
parent a9c8dfa6a8
commit 6f6284c21f
5 changed files with 79 additions and 16 deletions
@@ -591,7 +591,7 @@ class ComposerController extends BaseController
richTextMobileTabletController?.richTextController.hideRichTextView(); richTextMobileTabletController?.richTextController.hideRichTextView();
} }
autoCreateEmailTag(); autoCreateEmailTag();
triggerHideRecipientsFiledsWhenUnfocus(); triggerHideRecipientsFieldsWhenUnfocus();
} }
} }
@@ -1440,7 +1440,7 @@ class ComposerController extends BaseController
void clickOutsideComposer() { void clickOutsideComposer() {
clearFocus(); clearFocus();
triggerHideRecipientsFiledsWhenUnfocus(); triggerHideRecipientsFieldsWhenUnfocus();
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
refocusKeyboardShortcutFocus(); refocusKeyboardShortcutFocus();
} }
@@ -1718,7 +1718,7 @@ class ComposerController extends BaseController
richTextMobileTabletController?.richTextController.showDeviceKeyboard); richTextMobileTabletController?.richTextController.showDeviceKeyboard);
} }
autoCreateEmailTag(); autoCreateEmailTag();
triggerHideRecipientsFiledsWhenUnfocus(); triggerHideRecipientsFieldsWhenUnfocus();
} }
void _onChangeCursorOnMobile(List<int>? coordinates, BuildContext context) { void _onChangeCursorOnMobile(List<int>? coordinates, BuildContext context) {
@@ -1850,7 +1850,7 @@ class ComposerController extends BaseController
popBack(); popBack();
} }
autoCreateEmailTag(); autoCreateEmailTag();
triggerHideRecipientsFiledsWhenUnfocus(); triggerHideRecipientsFieldsWhenUnfocus();
} }
FocusNode? getNextFocusOfToEmailAddress() { 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 @override
Future<void> onBeforeReconnect() async { Future<void> onBeforeReconnect() async {
if (mailboxDashBoardController.accountId.value != null && if (mailboxDashBoardController.accountId.value != null &&
@@ -527,7 +527,7 @@ class ComposerView extends GetWidget<ComposerController> {
onClearFocusAction: controller.onClearFocusAction, onClearFocusAction: controller.onClearFocusAction,
onAddEmailAddressTypeAction: controller.addEmailAddressType, onAddEmailAddressTypeAction: controller.addEmailAddressType,
onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType, onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType,
onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputAction, onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputOnMobileAction,
)); ));
} }
} }
@@ -941,7 +941,7 @@ class ComposerView extends GetWidget<ComposerController> {
onClearFocusAction: controller.onClearFocusAction, onClearFocusAction: controller.onClearFocusAction,
onAddEmailAddressTypeAction: controller.addEmailAddressType, onAddEmailAddressTypeAction: controller.addEmailAddressType,
onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType, onDeleteEmailAddressTypeAction: controller.deleteEmailAddressType,
onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputAction, onEnableAllRecipientsInputAction: controller.handleEnableRecipientsInputOnMobileAction,
)); ));
} }
} }
@@ -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/composer_controller.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/prefix_recipient_state.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/features/email/presentation/utils/email_utils.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
extension HandleRecipientsCollapsedExtensions on ComposerController { extension HandleRecipientsCollapsedExtensions on ComposerController {
List<EmailAddress> get allListEmailAddress => List<EmailAddress> get allListEmailAddress =>
@@ -52,10 +53,22 @@ extension HandleRecipientsCollapsedExtensions on ComposerController {
replyToRecipientState.value = PrefixRecipientState.enabled; replyToRecipientState.value = PrefixRecipientState.enabled;
} }
if (currentContext != null &&
responsiveUtils.isMobile(currentContext!) &&
isAllRecipientInputEnabled) {
fromRecipientState.value = PrefixRecipientState.enabled;
}
updatePrefixRootState(); updatePrefixRootState();
requestFocusRecipientInput(); requestFocusRecipientInput();
} }
bool get isAllRecipientInputEnabled =>
toRecipientState.value == PrefixRecipientState.enabled &&
ccRecipientState.value == PrefixRecipientState.enabled &&
bccRecipientState.value == PrefixRecipientState.enabled &&
replyToRecipientState.value == PrefixRecipientState.enabled;
void updatePrefixRootState() { void updatePrefixRootState() {
if (toRecipientState.value == PrefixRecipientState.enabled) { if (toRecipientState.value == PrefixRecipientState.enabled) {
prefixRootState.value = PrefixEmailAddress.to; prefixRootState.value = PrefixEmailAddress.to;
@@ -98,7 +111,7 @@ extension HandleRecipientsCollapsedExtensions on ComposerController {
} }
} }
void triggerHideRecipientsFiledsWhenUnfocus() { void triggerHideRecipientsFieldsWhenUnfocus() {
if (isRecipientsEmptyExceptReplyTo) { if (isRecipientsEmptyExceptReplyTo) {
hideAllRecipientsFieldsExceptTo(); hideAllRecipientsFieldsExceptTo();
} else if (isRecipientsWithoutReplyToNotEmpty) { } else if (isRecipientsWithoutReplyToNotEmpty) {
@@ -123,4 +136,44 @@ extension HandleRecipientsCollapsedExtensions on ComposerController {
replyToRecipientState.value = PrefixRecipientState.disabled; replyToRecipientState.value = PrefixRecipientState.disabled;
recipientsCollapsedState.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;
}
} }
@@ -325,8 +325,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
), ),
if (widget.prefix == widget.prefixRootState && _isWeb && !isMobileResponsive) if (widget.prefix == widget.prefixRootState && _isWeb && !isMobileResponsive)
..._buildListPrefixWidgets(), ..._buildListPrefixWidgets(),
if (widget.prefix == widget.prefixRootState && (isMobileResponsive || widget.isTestingForWeb)) if (_isShowExpandButton(isMobileResponsive)) _buildExpandButton(),
_buildExpandButton(),
if (widget.prefix != widget.prefixRootState && _isWeb && !isMobileResponsive) if (widget.prefix != widget.prefixRootState && _isWeb && !isMobileResponsive)
TMailButtonWidget.fromIcon( TMailButtonWidget.fromIcon(
icon: widget.imagePaths.icClose, icon: widget.imagePaths.icClose,
@@ -400,6 +399,24 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
]; ];
} }
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() { Widget _buildExpandButton() {
return TMailButtonWidget.fromIcon( return TMailButtonWidget.fromIcon(
key: Key('prefix_${widget.prefix.name}_recipient_expand_button'), key: Key('prefix_${widget.prefix.name}_recipient_expand_button'),