Skip to content

Commit

Permalink
TF-3004 Fix open close advanced search looses data
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Oct 9, 2024
1 parent 3c66b25 commit 74e2acf
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:model/email/presentation_email.dart';
import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/quick_search_filter.dart';
import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';

Expand Down Expand Up @@ -56,15 +55,6 @@ class OpenEmailDetailedFromSuggestionQuickSearchAction extends DashBoardAction {

class StartSearchEmailAction extends DashBoardAction {}

class StartSearchEmailBySearchFilterAction extends DashBoardAction {
final QuickSearchFilter searchFilter;

StartSearchEmailBySearchFilterAction(this.searchFilter);

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

class EmptyTrashAction extends DashBoardAction {}

class ClearSearchEmailAction extends DashBoardAction {}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo

void handleAdvancedSearchEmail() {
log('MailboxDashBoardController::handleAdvancedSearchEmail:');
clearFilterMessageOption();
if (_searchInsideEmailDetailedViewIsActive()) {
_closeEmailDetailedView();
}
Expand Down Expand Up @@ -711,11 +710,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo

FocusManager.instance.primaryFocus?.unfocus();

if (isMailAddress) {
dispatchAction(StartSearchEmailBySearchFilterAction(QuickSearchFilter.from));
} else {
dispatchAction(StartSearchEmailAction());
}
dispatchAction(StartSearchEmailAction());
}

bool _searchInsideEmailDetailedViewIsActive() {
Expand Down Expand Up @@ -1715,7 +1710,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
.map((emailAddress) => emailAddress.emailAddress)
.toSet();
searchController.updateFilterEmail(fromOption: Some(listMailAddress));
dispatchAction(StartSearchEmailBySearchFilterAction(QuickSearchFilter.from));
dispatchAction(StartSearchEmailAction());
}
}

Expand All @@ -1738,7 +1733,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
.map((emailAddress) => emailAddress.emailAddress)
.toSet();
searchController.updateFilterEmail(toOption: Some(listMailAddress));
dispatchAction(StartSearchEmailBySearchFilterAction(QuickSearchFilter.to));
dispatchAction(StartSearchEmailAction());
}
}

Expand Down Expand Up @@ -1805,7 +1800,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
void selectSortOrderQuickSearchFilter(EmailSortOrderType sortOrder) {
log('MailboxDashBoardController::selectSortOrderQuickSearchFilter():sortOrder: $sortOrder');
popBack();
searchController.sortOrderFiltered.value = sortOrder;
searchController.updateFilterEmail(sortOrderTypeOption: Some(sortOrder));
dispatchAction(StartSearchEmailAction());
}

Expand All @@ -1820,18 +1815,19 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
}

void _deleteSortOrderSearchFilter() {
searchController.sortOrderFiltered.value = EmailSortOrderType.mostRecent;
searchController.updateFilterEmail(
sortOrderTypeOption: const Some(EmailSortOrderType.mostRecent));
dispatchAction(StartSearchEmailAction());
}

void _deleteFromSearchFilter() {
searchController.updateFilterEmail(fromOption: const None());
dispatchAction(StartSearchEmailBySearchFilterAction(QuickSearchFilter.from));
dispatchAction(StartSearchEmailAction());
}

void _deleteToSearchFilter() {
searchController.updateFilterEmail(toOption: const None());
dispatchAction(StartSearchEmailBySearchFilterAction(QuickSearchFilter.to));
dispatchAction(StartSearchEmailAction());
}

void _deleteHasAttachmentSearchFilter() {
Expand Down Expand Up @@ -2843,7 +2839,7 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
}

bool get isSearchFilterHasApplied {
return searchController.isSearchFilterHasApplied ||
return searchController.searchEmailFilter.value.isApplied ||
filterMessageOption.value != FilterMessageOption.all;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class SearchController extends BaseController with DateRangePickerMixin {
final listFilterOnSuggestionForm = RxList<QuickSearchFilter>();
final simpleSearchIsActivated = RxBool(false);
final advancedSearchIsActivated = RxBool(false);
final sortOrderFiltered = EmailSortOrderType.mostRecent.obs;

SearchQuery? get searchQuery => searchEmailFilter.value.text;

Expand Down Expand Up @@ -164,27 +163,31 @@ class SearchController extends BaseController with DateRangePickerMixin {
Option<SearchQuery>? textOption,
Option<String>? subjectOption,
Option<Set<String>>? notKeywordOption,
Option<Set<String>>? hasKeywordOption,
Option<PresentationMailbox>? mailboxOption,
Option<EmailReceiveTimeType>? emailReceiveTimeTypeOption,
Option<bool>? hasAttachmentOption,
Option<UTCDate>? beforeOption,
Option<UTCDate>? startDateOption,
Option<UTCDate>? endDateOption,
Option<int>? positionOption,
Option<EmailSortOrderType>? sortOrderTypeOption,
}) {
searchEmailFilter.value = searchEmailFilter.value.copyWith(
fromOption: fromOption,
toOption: toOption,
textOption: textOption,
subjectOption: subjectOption,
notKeywordOption: notKeywordOption,
hasKeywordOption: hasKeywordOption,
mailboxOption: mailboxOption,
emailReceiveTimeTypeOption: emailReceiveTimeTypeOption,
hasAttachmentOption: hasAttachmentOption,
beforeOption: beforeOption,
startDateOption: startDateOption,
endDateOption: endDateOption,
positionOption: positionOption,
sortOrderTypeOption: sortOrderTypeOption,
);
searchEmailFilter.refresh();
}
Expand All @@ -201,20 +204,13 @@ class SearchController extends BaseController with DateRangePickerMixin {

Set<String> get listAddressOfFromFiltered => searchEmailFilter.value.from;

EmailSortOrderType get sortOrderFiltered => searchEmailFilter.value.sortOrderType;

bool isSearchActive() =>
searchState.value.searchStatus == SearchStatus.ACTIVE;

bool get isSearchEmailRunning => simpleSearchIsActivated.isTrue || advancedSearchIsActivated.isTrue;

bool get isSearchFilterHasApplied {
return searchEmailFilter.value.from.isNotEmpty ||
searchEmailFilter.value.to.isNotEmpty ||
searchEmailFilter.value.emailReceiveTimeType != EmailReceiveTimeType.allTime ||
(searchEmailFilter.value.mailbox != PresentationMailbox.unifiedMailbox && searchEmailFilter.value.mailbox != null) ||
searchEmailFilter.value.hasAttachment == true ||
sortOrderFiltered.value != EmailSortOrderType.mostRecent;
}

void enableSearch() {
searchState.value = searchState.value.enableSearchState();
}
Expand Down Expand Up @@ -277,14 +273,9 @@ class SearchController extends BaseController with DateRangePickerMixin {
searchInputController.clear();
searchFocus.unfocus();
}

void clearSortOrder() {
sortOrderFiltered.value = EmailSortOrderType.mostRecent;
}

void clearAllFilterSearch() {
_clearAllTextInputSimpleSearch();
clearSortOrder();
clearFilterSuggestion();
clearSearchFilter();
deactivateAdvancedSearch();
Expand All @@ -296,7 +287,6 @@ class SearchController extends BaseController with DateRangePickerMixin {
deactivateSimpleSearch();
hideSimpleSearchFormView();

clearSortOrder();
clearSearchFilter();
deactivateAdvancedSearch();
hideAdvancedSearchFormView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
) {
return Obx(() {
final searchEmailFilter = controller.searchController.searchEmailFilter.value;
final sortOrderType = controller.searchController.sortOrderFiltered.value;
final sortOrderType = controller.searchController.sortOrderFiltered;
final listAddressOfFrom = controller.searchController.listAddressOfFromFiltered;
final userName = controller.sessionCurrent?.username;
final startDate = controller.searchController.startDateFiltered;
Expand Down Expand Up @@ -668,7 +668,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
position,
popupMenuEmailSortOrderType(
context,
controller.searchController.sortOrderFiltered.value,
controller.searchController.sortOrderFiltered,
onCallBack: controller.selectSortOrderQuickSearchFilter
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,33 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
final UTCDate? startDate;
final UTCDate? endDate;
final int? position;
final EmailSortOrderType sortOrderType;

factory SearchEmailFilter.initial() => SearchEmailFilter();

SearchEmailFilter({
Set<String>? from,
Set<String>? to,
EmailReceiveTimeType? emailReceiveTimeType,
bool? hasAttachment,
this.text,
this.subject,
Set<String>? notKeyword,
Set<String>? hasKeyword,
this.mailbox,
this.before,
this.startDate,
this.endDate,
this.position,
Set<String>? from,
Set<String>? to,
EmailReceiveTimeType? emailReceiveTimeType,
bool? hasAttachment,
Set<String>? notKeyword,
Set<String>? hasKeyword,
EmailSortOrderType? sortOrderType,
}) : from = from ?? <String>{},
to = to ?? <String>{},
notKeyword = notKeyword ?? <String>{},
hasKeyword = hasKeyword ?? <String>{},
hasAttachment = hasAttachment ?? false,
emailReceiveTimeType =
emailReceiveTimeType ?? EmailReceiveTimeType.allTime;
emailReceiveTimeType ?? EmailReceiveTimeType.allTime,
sortOrderType = sortOrderType ?? EmailSortOrderType.mostRecent;

SearchEmailFilter copyWith({
Option<Set<String>>? fromOption,
Expand All @@ -67,6 +70,7 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
Option<UTCDate>? startDateOption,
Option<UTCDate>? endDateOption,
Option<int>? positionOption,
Option<EmailSortOrderType>? sortOrderTypeOption,
}) {
return SearchEmailFilter(
from: getOptionParam(fromOption, from),
Expand All @@ -82,24 +86,24 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
startDate: getOptionParam(startDateOption, startDate),
endDate: getOptionParam(endDateOption, endDate),
position: getOptionParam(positionOption, position),
sortOrderType: getOptionParam(sortOrderTypeOption, sortOrderType),
);
}

Filter? mappingToEmailFilterCondition({
required EmailSortOrderType sortOrderType,
EmailFilterCondition? moreFilterCondition
}) {
final emailEmailFilterConditionShared = EmailFilterCondition(
text: text?.value.trim().isNotEmpty == true
? text?.value
? text?.value.trim()
: null,
inMailbox: mailbox?.mailboxId,
after: sortOrderType.isScrollByPosition()
? null
: emailReceiveTimeType.getAfterDate(startDate),
hasAttachment: hasAttachment == false ? null : hasAttachment,
hasAttachment: !hasAttachment ? null : hasAttachment,
subject: subject?.trim().isNotEmpty == true
? subject
? subject?.trim()
: null,
before: sortOrderType.isScrollByPosition()
? null
Expand Down Expand Up @@ -145,6 +149,17 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
}
}

bool get isApplied => from.isNotEmpty ||
to.isNotEmpty ||
text?.value.trim().isNotEmpty == true ||
subject?.trim().isNotEmpty == true ||
hasKeyword.isNotEmpty == true ||
notKeyword.isNotEmpty == true ||
emailReceiveTimeType != EmailReceiveTimeType.allTime ||
sortOrderType != EmailSortOrderType.mostRecent ||
(mailbox != null && mailbox?.id != PresentationMailbox.unifiedMailbox.id) ||
hasAttachment;

@override
List<Object?> get props => [
from,
Expand All @@ -160,5 +175,6 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin {
startDate,
endDate,
position,
sortOrderType
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';

class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterController> {

final InputFieldFocusManager? focusManager;
final InputFieldFocusManager focusManager;

const AdvancedSearchFilterFormBottomView({
Key? key,
this.focusManager,
required this.focusManager,
}) : super(key: key);

@override
Expand All @@ -30,8 +30,8 @@ class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterControl
transform: Matrix4.translationValues(-8.0, 0.0, 0.0),
child: _buildCheckboxHasAttachment(
context,
currentFocusNode: focusManager?.attachmentCheckboxFocusNode,
nextFocusNode: focusManager?.searchButtonFocusNode),
currentFocusNode: focusManager.attachmentCheckboxFocusNode,
nextFocusNode: focusManager.searchButtonFocusNode),
),
_buildListButton(context, controller.responsiveUtils),
],
Expand Down Expand Up @@ -67,8 +67,8 @@ class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterControl
text: AppLocalizations.of(context).search,
context: context,
responsiveUtils: responsiveUtils,
currentFocusNode: focusManager?.searchButtonFocusNode,
nextFocusNode: focusManager?.fromFieldFocusNode
currentFocusNode: focusManager.searchButtonFocusNode,
nextFocusNode: focusManager.fromFieldFocusNode
),
),
]);
Expand Down Expand Up @@ -99,8 +99,8 @@ class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterControl
context: context,
responsiveUtils: responsiveUtils,
minWidth: 144,
currentFocusNode: focusManager?.searchButtonFocusNode,
nextFocusNode: focusManager?.fromFieldFocusNode
currentFocusNode: focusManager.searchButtonFocusNode,
nextFocusNode: focusManager.fromFieldFocusNode
),
]);
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterControl
contentPadding: EdgeInsets.zero,
value: controller.hasAttachment.value,
activeColor: AppColor.primaryColor,
onChanged: (value) => controller.hasAttachment.value = value ?? false,
onChanged: controller.onHasAttachmentCheckboxChanged,
),
),
);
Expand Down
Loading

0 comments on commit 74e2acf

Please sign in to comment.