diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index 1a7ccee74..11e878906 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -844,11 +844,7 @@ class MailboxController extends BaseMailboxController void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async { if (session != null && accountId != null) { - final arguments = MailboxCreatorArguments( - defaultMailboxTree.value, - personalMailboxTree.value, - parentMailbox, - ); + final arguments = MailboxCreatorArguments(allMailboxes, parentMailbox); final result = PlatformInfo.isWeb ? await DialogRouter.pushGeneralDialog(routeName: AppRoutes.mailboxCreator, arguments: arguments) diff --git a/lib/features/mailbox/presentation/model/mailbox_tree_builder.dart b/lib/features/mailbox/presentation/model/mailbox_tree_builder.dart index 74430b06a..d749a8126 100644 --- a/lib/features/mailbox/presentation/model/mailbox_tree_builder.dart +++ b/lib/features/mailbox/presentation/model/mailbox_tree_builder.dart @@ -48,6 +48,7 @@ class TreeBuilder { required MailboxTree currentPersonalTree, required MailboxTree currentTeamMailboxTree, MailboxId? mailboxIdSelected, + MailboxId? mailboxIdExpanded, }) async { final Map mailboxDictionary = HashMap(); diff --git a/lib/features/mailbox_creator/presentation/mailbox_creator_bindings.dart b/lib/features/mailbox_creator/presentation/mailbox_creator_bindings.dart index 00f7a1e34..1d31fa119 100644 --- a/lib/features/mailbox_creator/presentation/mailbox_creator_bindings.dart +++ b/lib/features/mailbox_creator/presentation/mailbox_creator_bindings.dart @@ -1,4 +1,5 @@ import 'package:get/get.dart'; +import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_controller.dart'; @@ -6,7 +7,11 @@ class MailboxCreatorBindings extends Bindings { @override void dependencies() { + Get.lazyPut(() => TreeBuilder()); Get.lazyPut(() => VerifyNameInteractor()); - Get.lazyPut(() => MailboxCreatorController(Get.find())); + Get.lazyPut(() => MailboxCreatorController( + Get.find(), + Get.find(), + )); } } \ No newline at end of file diff --git a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart index 30178e2de..27b75b506 100644 --- a/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart +++ b/lib/features/mailbox_creator/presentation/mailbox_creator_controller.dart @@ -7,6 +7,7 @@ import 'package:tmail_ui_user/features/base/mixin/expand_folder_trigger_scrollab import 'package:tmail_ui_user/features/mailbox/presentation/extensions/expand_mode_extension.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/presentation/model/mailbox_tree_builder.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/name_with_space_only_validator.dart'; @@ -25,6 +26,7 @@ class MailboxCreatorController extends BaseController with ExpandFolderTriggerScrollableMixin { final VerifyNameInteractor _verifyNameInteractor; + final TreeBuilder _treeBuilder; final selectedMailbox = Rxn(); final newNameMailbox = Rxn(); @@ -40,7 +42,7 @@ class MailboxCreatorController extends BaseController List listMailboxNameAsStringExist = []; - MailboxCreatorController(this._verifyNameInteractor); + MailboxCreatorController(this._verifyNameInteractor, this._treeBuilder); void setNewNameMailbox(String newName) => newNameMailbox.value = newName; @@ -49,10 +51,7 @@ class MailboxCreatorController extends BaseController super.onInit(); MailboxCreatorArguments? arguments = Get.arguments; if (arguments != null) { - personalMailboxTree.value = arguments.personalMailboxTree; - defaultMailboxTree.value = arguments.defaultMailboxTree; - selectedMailbox.value = arguments.selectedMailbox; - _createListMailboxNameAsStringInMailboxLocation(); + _buildMailboxTree(arguments); } } @@ -66,6 +65,19 @@ class MailboxCreatorController extends BaseController super.onClose(); } + Future _buildMailboxTree(MailboxCreatorArguments arguments) async { + final recordTree = await _treeBuilder.generateMailboxTreeInUI( + allMailboxes: arguments.listMailboxes, + currentDefaultTree: defaultMailboxTree.value, + currentPersonalTree: personalMailboxTree.value, + currentTeamMailboxTree: MailboxTree(MailboxNode.root()), + ); + personalMailboxTree.value = recordTree.personalTree; + defaultMailboxTree.value = recordTree.defaultTree; + selectedMailbox.value = arguments.selectedMailbox; + _createListMailboxNameAsStringInMailboxLocation(); + } + MailboxNode? _findMailboxNodeById(MailboxId mailboxId) { final mailboxNode = defaultMailboxTree.value.findNode((node) => node.item.id == mailboxId) ?? personalMailboxTree.value.findNode((node) => node.item.id == mailboxId); diff --git a/lib/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart b/lib/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart index 477681544..9c548891d 100644 --- a/lib/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart +++ b/lib/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart @@ -1,23 +1,12 @@ - import 'package:equatable/equatable.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 MailboxTree personalMailboxTree; - final MailboxTree defaultMailboxTree; +class MailboxCreatorArguments with EquatableMixin { + final List listMailboxes; final PresentationMailbox? selectedMailbox; - MailboxCreatorArguments( - this.defaultMailboxTree, - this.personalMailboxTree, - this.selectedMailbox, - ); + MailboxCreatorArguments(this.listMailboxes, this.selectedMailbox); @override - List get props => [ - defaultMailboxTree, - personalMailboxTree, - selectedMailbox, - ]; -} \ No newline at end of file + List get props => [listMailboxes, selectedMailbox]; +} diff --git a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart index d7459b1a1..bd4ba8233 100644 --- a/lib/features/search/mailbox/presentation/search_mailbox_controller.dart +++ b/lib/features/search/mailbox/presentation/search_mailbox_controller.dart @@ -755,11 +755,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async { if (session != null && accountId != null) { - final arguments = MailboxCreatorArguments( - defaultMailboxTree.value, - personalMailboxTree.value, - parentMailbox, - ); + final arguments = MailboxCreatorArguments(allMailboxes, parentMailbox); final result = PlatformInfo.isWeb ? await DialogRouter.pushGeneralDialog(routeName: AppRoutes.mailboxCreator, arguments: arguments)