Skip to content

Commit

Permalink
TF-2194 Add case subFolder to search mailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui authored and dab246 committed Oct 6, 2023
1 parent 84ca809 commit ee0b9b3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
_openMailboxEventController.add(OpenMailboxViewEvent(context, presentationMailboxSelected));
}

void goToCreateNewMailboxView(BuildContext context, PresentationMailbox? parentMailbox) async {
void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async {
final accountId = mailboxDashBoardController.accountId.value;
final session = mailboxDashBoardController.sessionCurrent;
if (session !=null && accountId != null) {
Expand Down Expand Up @@ -953,7 +953,7 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
emptySpamAction(context, mailbox, mailboxDashBoardController);
break;
case MailboxActions.newSubfolder:
goToCreateNewMailboxView(context, mailbox);
goToCreateNewMailboxView(context, parentMailbox: mailbox);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/features/mailbox/presentation/mailbox_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class MailboxView extends BaseMailboxView {
colorFilter: AppColor.colorTextButton.asFilter(),
fit: BoxFit.fill),
tooltip: AppLocalizations.of(context).new_mailbox,
onTap: () => controller.goToCreateNewMailboxView(context, null)),
onTap: () => controller.goToCreateNewMailboxView(context)),
]),
]),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/mailbox/presentation/mailbox_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class MailboxView extends BaseMailboxView {
colorFilter: AppColor.colorTextButton.asFilter(),
fit: BoxFit.fill),
tooltip: AppLocalizations.of(context).new_mailbox,
onTap: () => controller.goToCreateNewMailboxView(context, null)),
onTap: () => controller.goToCreateNewMailboxView(context)),
],
)),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart';
import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/delete_multiple_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/move_mailbox_interactor.dart';
Expand All @@ -38,6 +39,7 @@ class SearchMailboxBindings extends BaseBindings {
Get.find<DeleteMultipleMailboxInteractor>(),
Get.find<SubscribeMailboxInteractor>(),
Get.find<SubscribeMultipleMailboxInteractor>(),
Get.find<CreateNewMailboxInteractor>(),
Get.find<TreeBuilder>(),
Get.find<VerifyNameInteractor>(),
Get.find<GetAllMailboxInteractor>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/email/presentation_email.dart';
Expand All @@ -21,13 +23,15 @@ import 'package:tmail_ui_user/features/base/base_mailbox_controller.dart';
import 'package:debounce_throttle/debounce_throttle.dart';
import 'package:tmail_ui_user/features/base/mixin/mailbox_action_handler_mixin.dart';
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/move_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/create_new_mailbox_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/delete_multiple_mailbox_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart';
Expand All @@ -37,6 +41,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/state/rename_mailbox_state
import 'package:tmail_ui_user/features/mailbox/domain/state/search_mailbox_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/subscribe_mailbox_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/subscribe_multiple_mailbox_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/delete_multiple_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/move_mailbox_interactor.dart';
Expand All @@ -51,13 +56,18 @@ import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_action
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/utils/mailbox_utils.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_mailbox_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
import 'package:tmail_ui_user/features/search/mailbox/presentation/search_mailbox_bindings.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/app_routes.dart';
import 'package:tmail_ui_user/main/routes/dialog_router.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:uuid/uuid.dart';

class SearchMailboxController extends BaseMailboxController with MailboxActionHandlerMixin {

Expand All @@ -67,11 +77,13 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
final DeleteMultipleMailboxInteractor _deleteMultipleMailboxInteractor;
final SubscribeMailboxInteractor _subscribeMailboxInteractor;
final SubscribeMultipleMailboxInteractor _subscribeMultipleMailboxInteractor;
final CreateNewMailboxInteractor _createNewMailboxInteractor;

final dashboardController = Get.find<MailboxDashBoardController>();
final responsiveUtils = Get.find<ResponsiveUtils>();
final imagePaths = Get.find<ImagePaths>();
final _appToast = Get.find<AppToast>();
final _uuid = Get.find<Uuid>();

final currentSearchQuery = RxString('');
final listMailboxSearched = RxList<PresentationMailbox>();
Expand All @@ -89,6 +101,7 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
this._deleteMultipleMailboxInteractor,
this._subscribeMailboxInteractor,
this._subscribeMultipleMailboxInteractor,
this._createNewMailboxInteractor,
TreeBuilder treeBuilder,
VerifyNameInteractor verifyNameInteractor,
GetAllMailboxInteractor getAllMailboxInteractor,
Expand All @@ -112,6 +125,8 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
super.handleFailureViewState(failure);
if (failure is SearchMailboxFailure) {
_handleSearchMailboxFailure(failure);
} else if (failure is CreateNewMailboxFailure) {
_createNewMailboxFailure(failure);
}
}

Expand Down Expand Up @@ -151,6 +166,8 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
_handleSubscribeMultipleMailboxAllSuccess(success);
} else if (success is SubscribeMultipleMailboxHasSomeSuccess) {
_handleSubscribeMultipleMailboxHasSomeSuccess(success);
} else if (success is CreateNewMailboxSuccess) {
_createNewMailboxSuccess(success);
}
}

Expand Down Expand Up @@ -297,6 +314,9 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
case MailboxActions.emptySpam:
emptySpamAction(context, mailbox, dashboardController);
break;
case MailboxActions.newSubfolder:
goToCreateNewMailboxView(context, parentMailbox: mailbox);
break;
default:
break;
}
Expand Down Expand Up @@ -622,6 +642,60 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
}
}

void goToCreateNewMailboxView(BuildContext context, {PresentationMailbox? parentMailbox}) async {
final accountId = dashboardController.accountId.value;
final session = dashboardController.sessionCurrent;
if (session != null && accountId != null) {
final arguments = MailboxCreatorArguments(
accountId,
defaultMailboxTree.value,
personalMailboxTree.value,
teamMailboxesTree.value,
dashboardController.sessionCurrent!,
parentMailbox
);

final result = PlatformInfo.isWeb
? await DialogRouter.pushGeneralDialog(routeName: AppRoutes.mailboxCreator, arguments: arguments)
: await push(AppRoutes.mailboxCreator, arguments: arguments);

if (result != null && result is NewMailboxArguments) {
final generateCreateId = Id(_uuid.v1());
_createNewMailboxAction(session, accountId, CreateNewMailboxRequest(
generateCreateId,
result.newName,
parentId: result.mailboxLocation?.id));
}
}
}

void _createNewMailboxAction(Session session, AccountId accountId, CreateNewMailboxRequest request) async {
consumeState(_createNewMailboxInteractor.execute(session, accountId, request));
}

void _createNewMailboxSuccess(CreateNewMailboxSuccess success) {
if (currentOverlayContext != null && currentContext != null) {
_appToast.showToastSuccessMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).createFolderSuccessfullyMessage(success.newMailbox.name?.name ?? ''),
leadingSVGIconColor: Colors.white,
leadingSVGIcon: imagePaths.icFolderMailbox);
}

_refreshMailboxChanges(mailboxState: success.currentMailboxState);
}

void _createNewMailboxFailure(CreateNewMailboxFailure failure) {
if (currentOverlayContext != null && currentContext != null) {
final exception = failure.exception;
var messageError = AppLocalizations.of(currentContext!).create_new_mailbox_failure;
if (exception is ErrorMethodResponse) {
messageError = exception.description ?? AppLocalizations.of(currentContext!).create_new_mailbox_failure;
}
_appToast.showToastErrorMessage(currentOverlayContext!, messageError);
}
}

void clearAllTextInputSearchForm() {
textInputSearchController.clear();
currentSearchQuery.value = '';
Expand Down

0 comments on commit ee0b9b3

Please sign in to comment.