TF-333 Create 2 mailbox with the same name in MailboxCreatorView

This commit is contained in:
dab246
2022-03-29 18:37:34 +07:00
committed by Dat H. Pham
parent a2eac30f1b
commit 869053c6eb
3 changed files with 42 additions and 12 deletions
@@ -294,7 +294,7 @@ class MailboxController extends BaseMailboxController {
if (accountId != null) {
final newMailboxArguments = await push(
AppRoutes.MAILBOX_CREATOR,
arguments: MailboxCreatorArguments(accountId, allMailboxes)
arguments: MailboxCreatorArguments(accountId, defaultMailboxTree.value, folderMailboxTree.value)
);
if (newMailboxArguments != null && newMailboxArguments is NewMailboxArguments) {
@@ -9,6 +9,8 @@ import 'package:model/model.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/duplicate_name_validator.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/empty_name_validator.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/special_character_validator.dart';
@@ -27,8 +29,10 @@ class MailboxCreatorController extends BaseController {
final selectedMailbox = Rxn<PresentationMailbox>();
final newNameMailbox = Rxn<String>();
List<PresentationMailbox> allMailboxes = <PresentationMailbox>[];
AccountId? accountId;
MailboxTree? folderMailboxTree;
MailboxTree? defaultMailboxTree;
List<String> listMailboxNameAsStringExist = <String>[];
MailboxCreatorController(
this._verifyNameInteractor,
@@ -41,9 +45,12 @@ class MailboxCreatorController extends BaseController {
super.onReady();
final arguments = Get.arguments;
if (arguments is MailboxCreatorArguments) {
allMailboxes = arguments.allMailboxes;
folderMailboxTree = arguments.folderMailboxTree;
defaultMailboxTree = arguments.defaultMailboxTree;
accountId = arguments.accountId;
log('allMailboxes: $allMailboxes | accountId: $accountId');
log('MailboxCreatorController::onReady(): defaultMailboxTree: $defaultMailboxTree');
log('MailboxCreatorController::onReady(): folderMailboxTree: $folderMailboxTree');
_createListMailboxNameAsStringInMailboxLocation();
}
}
@@ -67,17 +74,38 @@ class MailboxCreatorController extends BaseController {
return true;
}
void _createListMailboxNameAsStringInMailboxLocation() {
if (selectedMailbox.value == null) {
final allChildrenAtMailboxLocation = (defaultMailboxTree?.root.childrenItems ?? <MailboxNode>[]) + (folderMailboxTree?.root.childrenItems ?? <MailboxNode>[]);
if (allChildrenAtMailboxLocation.isNotEmpty) {
listMailboxNameAsStringExist = allChildrenAtMailboxLocation
.where((mailboxNode) => mailboxNode.item.name != null && mailboxNode.item.name?.name.isNotEmpty == true)
.map((mailboxNode) => mailboxNode.item.name!.name)
.toList();
}
} else {
final mailboxNodeLocation = defaultMailboxTree?.findNode((node) => node.item.id == selectedMailbox.value!.id)
?? folderMailboxTree?.findNode((node) => node.item.id == selectedMailbox.value!.id);
if (mailboxNodeLocation != null && mailboxNodeLocation.childrenItems?.isNotEmpty == true) {
final allChildrenAtMailboxLocation = mailboxNodeLocation.childrenItems!;
listMailboxNameAsStringExist = allChildrenAtMailboxLocation
.where((mailboxNode) => mailboxNode.item.name != null && mailboxNode.item.name?.name.isNotEmpty == true)
.map((mailboxNode) => mailboxNode.item.name!.name)
.toList();
}
}
log('MailboxCreatorController::_createListMailboxNameAsStringInMailboxLocation(): ${listMailboxNameAsStringExist.toString()}');
}
String? getErrorInputNameString(BuildContext context) {
final nameMailbox = newNameMailbox.value;
final listName = allMailboxes
.where((mailbox) => !(mailbox.name.isBlank == true))
.map((mailbox) => mailbox.name!.name).toList();
return _verifyNameInteractor.execute(
nameMailbox,
[
EmptyNameValidator(),
DuplicateNameValidator(listName),
DuplicateNameValidator(listMailboxNameAsStringExist),
SpecialCharacterValidator(),
]
).fold(
@@ -102,6 +130,7 @@ class MailboxCreatorController extends BaseController {
);
selectedMailbox.value = destinationMailbox;
_createListMailboxNameAsStringInMailboxLocation();
}
}
@@ -1,14 +1,15 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
class MailboxCreatorArguments with EquatableMixin{
final AccountId accountId;
final List<PresentationMailbox> allMailboxes;
final MailboxTree folderMailboxTree;
final MailboxTree defaultMailboxTree;
MailboxCreatorArguments(this.accountId, this.allMailboxes);
MailboxCreatorArguments(this.accountId, this.defaultMailboxTree, this.folderMailboxTree);
@override
List<Object?> get props => [accountId, allMailboxes];
List<Object?> get props => [accountId, defaultMailboxTree, folderMailboxTree];
}