Skip to content

Commit

Permalink
TF-3002 [WEB] Remove BuildContext in action & optimize code for `Se…
Browse files Browse the repository at this point in the history
…archFilterButton/FilterMessageButton` widget
  • Loading branch information
dab246 committed Sep 16, 2024
1 parent 6f1c7b2 commit 348210d
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 338 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import 'package:flutter/cupertino.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/email/email_action_type.dart';
Expand Down Expand Up @@ -28,36 +27,33 @@ class CancelSelectionAllEmailAction extends DashBoardAction {}

class FilterMessageAction extends DashBoardAction {

final BuildContext context;
final FilterMessageOption option;

FilterMessageAction(this.context, this.option);
FilterMessageAction(this.option);

@override
List<Object?> get props => [context, option];
List<Object?> get props => [option];
}

class HandleEmailActionTypeAction extends DashBoardAction {

final BuildContext context;
final EmailActionType emailAction;
final List<PresentationEmail> listEmailSelected;

HandleEmailActionTypeAction(this.context, this.listEmailSelected, this.emailAction);
HandleEmailActionTypeAction(this.listEmailSelected, this.emailAction);

@override
List<Object> get props => [context, listEmailSelected, emailAction];
List<Object> get props => [listEmailSelected, emailAction];
}

class OpenEmailDetailedFromSuggestionQuickSearchAction extends DashBoardAction {

final BuildContext context;
final PresentationEmail presentationEmail;

OpenEmailDetailedFromSuggestionQuickSearchAction(this.context, this.presentationEmail);
OpenEmailDetailedFromSuggestionQuickSearchAction(this.presentationEmail);

@override
List<Object?> get props => [context, presentationEmail];
List<Object?> get props => [presentationEmail];
}

class StartSearchEmailAction extends DashBoardAction {
Expand All @@ -69,15 +65,7 @@ class StartSearchEmailAction extends DashBoardAction {
List<Object?> get props => [filter];
}

class EmptyTrashAction extends DashBoardAction {

final BuildContext context;

EmptyTrashAction(this.context);

@override
List<Object?> get props => [context];
}
class EmptyTrashAction extends DashBoardAction {}

class ClearSearchEmailAction extends DashBoardAction {}

Expand Down Expand Up @@ -165,20 +153,6 @@ class CloseSearchEmailViewAction extends DashBoardAction {}

class CancelSelectionSearchEmailAction extends DashBoardAction {}

class OpenAdvancedSearchViewAction extends DashBoardAction {
final BuildContext context;

OpenAdvancedSearchViewAction(this.context);
class OpenAdvancedSearchViewAction extends DashBoardAction {}

@override
List<Object?> get props => [context];
}

class ClearSearchFilterAppliedAction extends DashBoardAction {
final BuildContext context;

ClearSearchFilterAppliedAction(this.context);

@override
List<Object?> get props => [context];
}
class ClearSearchFilterAppliedAction extends DashBoardAction {}
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ class AdvancedFilterController extends BaseController {
searchController.updateFilterEmail(fromOption: Some(listAddress));

_mailboxDashBoardController.dispatchAction(StartSearchEmailAction());
} else if (action is OpenAdvancedSearchViewAction) {
initSearchFilterField(action.context);
} else if (action is ClearSearchFilterAppliedAction) {
clearSearchFilter(action.context);
} else if (action is OpenAdvancedSearchViewAction && currentContext != null) {
initSearchFilterField(currentContext!);
} else if (action is ClearSearchFilterAppliedAction && currentContext != null) {
clearSearchFilter(currentContext!);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,6 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
}

void moveSelectedMultipleEmailToMailbox(
BuildContext context,
List<PresentationEmail> listEmails,
PresentationMailbox currentMailbox
) async {
Expand Down Expand Up @@ -1856,8 +1855,8 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
!responsiveUtils.isWebDesktop(context);
}

void emptyTrashAction(BuildContext context) {
dispatchAction(EmptyTrashAction(context));
void emptyTrashAction() {
dispatchAction(EmptyTrashAction());
}

void showAppDashboardAction() async {
Expand Down Expand Up @@ -2783,13 +2782,13 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
filterMessageOption.value != FilterMessageOption.all;
}

void openAdvancedSearchView(BuildContext context) {
dispatchAction(OpenAdvancedSearchViewAction(context));
void openAdvancedSearchView() {
dispatchAction(OpenAdvancedSearchViewAction());
searchController.openAdvanceSearch();
}

void clearAllSearchFilterApplied(BuildContext context) {
dispatchAction(ClearSearchFilterAppliedAction(context));
void clearAllSearchFilterApplied() {
dispatchAction(ClearSearchFilterAppliedAction());
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
Obx(() {
if (controller.isEmptyTrashBannerEnabledOnWeb(context)) {
return BannerEmptyTrashWidget(
onTapAction: () => controller.emptyTrashAction(context)
onTapAction: controller.emptyTrashAction
);
} else {
return const SizedBox.shrink();
Expand Down Expand Up @@ -235,7 +235,6 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
controller.dispatchAction(CancelSelectionAllEmailAction()),
onEmailActionTypeAction: (listEmails, actionType) =>
controller.dispatchAction(HandleEmailActionTypeAction(
context,
listEmails,
actionType
)),
Expand Down Expand Up @@ -366,7 +365,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
imagePaths: controller.imagePaths,
isSelected: filterMessageCurrent != FilterMessageOption.all,
onSelectFilterMessageOptionAction: _onSelectFilterMessageOptionAction,
onDeleteFilterMessageOptionAction: (_) => _onDeleteFilterMessageOptionAction(context),
onDeleteFilterMessageOptionAction: (_) => _onDeleteFilterMessageOptionAction(),
),
);
}
Expand Down Expand Up @@ -410,17 +409,15 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
context,
filterMessageCurrent,
(filterMessageSelected) {
controller.dispatchAction(FilterMessageAction(
context,
filterMessageSelected));
controller.dispatchAction(FilterMessageAction(filterMessageSelected));
},
isSearchEmailRunning: controller.searchController.isSearchEmailRunning
)
);
}

void _onDeleteFilterMessageOptionAction(BuildContext context) {
controller.dispatchAction(FilterMessageAction(context, FilterMessageOption.all));
void _onDeleteFilterMessageOptionAction() {
controller.dispatchAction(FilterMessageAction(FilterMessageOption.all));
}

Widget _buildDownloadTaskStateWidget() {
Expand Down Expand Up @@ -522,7 +519,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
color: AppColor.primaryColor,
fontSize: 13,
fontWeight: FontWeight.w500),
onTapActionCallback: () => controller.clearAllSearchFilterApplied(context))
onTapActionCallback: controller.clearAllSearchFilterApplied)
else
TMailButtonWidget.fromText(
text: AppLocalizations.of(context).advancedSearch,
Expand All @@ -533,7 +530,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
color: AppColor.primaryColor,
fontSize: 13,
fontWeight: FontWeight.w500),
onTapActionCallback: () => controller.openAdvancedSearchView(context))
onTapActionCallback: controller.openAdvancedSearchView)
]
),
);
Expand Down
Loading

0 comments on commit 348210d

Please sign in to comment.