TF-4013 Collapse all recipients fields when unfocus
(cherry picked from commit cd2c2db33a242d22a06265dca5fa4601753957ab)
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/email/prefix_email_address.dart';
|
||||
import 'package:model/extensions/email_address_extension.dart';
|
||||
import 'package:model/mailbox/expand_mode.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';
|
||||
|
||||
extension HandleRecipientsCollapsedExtensions on ComposerController {
|
||||
List<EmailAddress> get allListEmailAddress =>
|
||||
listToEmailAddress +
|
||||
listCcEmailAddress +
|
||||
listBccEmailAddress +
|
||||
listReplyToEmailAddress;
|
||||
|
||||
List<EmailAddress> get listEmailAddressInvalid => allListEmailAddress
|
||||
.where(
|
||||
(emailAddress) => !EmailUtils.isEmailAddressValid(
|
||||
emailAddress.emailAddress,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
bool get isRecipientsNotEmpty => listToEmailAddress.isNotEmpty ||
|
||||
listCcEmailAddress.isNotEmpty ||
|
||||
listBccEmailAddress.isNotEmpty ||
|
||||
listReplyToEmailAddress.isNotEmpty;
|
||||
|
||||
void showFullRecipients() {
|
||||
updatePrefixRootState();
|
||||
recipientsCollapsedState.value = PrefixRecipientState.disabled;
|
||||
|
||||
if (listToEmailAddress.isNotEmpty) {
|
||||
toRecipientState.value = PrefixRecipientState.enabled;
|
||||
toAddressExpandMode.value = ExpandMode.EXPAND;
|
||||
}
|
||||
|
||||
if (listCcEmailAddress.isNotEmpty) {
|
||||
ccRecipientState.value = PrefixRecipientState.enabled;
|
||||
ccAddressExpandMode.value = ExpandMode.EXPAND;
|
||||
}
|
||||
|
||||
if (listBccEmailAddress.isNotEmpty) {
|
||||
bccRecipientState.value = PrefixRecipientState.enabled;
|
||||
bccAddressExpandMode.value = ExpandMode.EXPAND;
|
||||
}
|
||||
|
||||
if (listReplyToEmailAddress.isNotEmpty) {
|
||||
replyToRecipientState.value = PrefixRecipientState.enabled;
|
||||
replyToAddressExpandMode.value = ExpandMode.EXPAND;
|
||||
}
|
||||
|
||||
requestFocusRecipientInput();
|
||||
}
|
||||
|
||||
void updatePrefixRootState() {
|
||||
if (listToEmailAddress.isNotEmpty) {
|
||||
prefixRootState = PrefixEmailAddress.to;
|
||||
return;
|
||||
}
|
||||
|
||||
if (listCcEmailAddress.isNotEmpty) {
|
||||
prefixRootState = PrefixEmailAddress.cc;
|
||||
return;
|
||||
}
|
||||
|
||||
if (listBccEmailAddress.isNotEmpty) {
|
||||
prefixRootState = PrefixEmailAddress.bcc;
|
||||
return;
|
||||
}
|
||||
|
||||
if (listReplyToEmailAddress.isNotEmpty) {
|
||||
prefixRootState = PrefixEmailAddress.replyTo;
|
||||
}
|
||||
}
|
||||
|
||||
void requestFocusRecipientInput() {
|
||||
if (listToEmailAddress.isNotEmpty) {
|
||||
toAddressFocusNode?.requestFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (listCcEmailAddress.isNotEmpty) {
|
||||
ccAddressFocusNode?.requestFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (listBccEmailAddress.isNotEmpty) {
|
||||
bccAddressFocusNode?.requestFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (listReplyToEmailAddress.isNotEmpty) {
|
||||
replyToAddressFocusNode?.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void hideAllRecipients() {
|
||||
toRecipientState.value = PrefixRecipientState.disabled;
|
||||
ccRecipientState.value = PrefixRecipientState.disabled;
|
||||
bccRecipientState.value = PrefixRecipientState.disabled;
|
||||
replyToRecipientState.value = PrefixRecipientState.disabled;
|
||||
recipientsCollapsedState.value = PrefixRecipientState.enabled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user