diff --git a/lib/features/mailbox_dashboard/presentation/model/search/search_email_filter.dart b/lib/features/mailbox_dashboard/presentation/model/search/search_email_filter.dart index 577e4db6e7..526430daa6 100644 --- a/lib/features/mailbox_dashboard/presentation/model/search/search_email_filter.dart +++ b/lib/features/mailbox_dashboard/presentation/model/search/search_email_filter.dart @@ -1,7 +1,6 @@ -import 'package:core/core.dart'; +import 'package:core/utils/option_param_mixin.dart'; import 'package:dartz/dartz.dart'; import 'package:equatable/equatable.dart'; -import 'package:flutter/material.dart'; import 'package:jmap_dart_client/jmap/core/filter/filter.dart'; import 'package:jmap_dart_client/jmap/core/filter/filter_operator.dart'; import 'package:jmap_dart_client/jmap/core/filter/operator/logic_filter_operator.dart'; @@ -12,11 +11,9 @@ import 'package:model/email/prefix_email_address.dart'; import 'package:model/extensions/email_filter_condition_extension.dart'; import 'package:model/extensions/presentation_mailbox_extension.dart'; import 'package:model/mailbox/presentation_mailbox.dart'; -import 'package:tmail_ui_user/features/mailbox/presentation/extensions/presentation_mailbox_extension.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/email_sort_order_type.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart'; -import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; class SearchEmailFilter with EquatableMixin, OptionParamMixin { final Set from; @@ -155,47 +152,6 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin { } } - bool get searchFilterByMailboxApplied => mailbox != null; - - String getMailboxName(BuildContext context) => mailbox?.getDisplayName(context) ?? ''; - - bool get searchFilterByFromApplied => from.isNotEmpty; - - bool get searchFilterByToApplied => to.isNotEmpty; - - bool searchFilterByContactApplied(PrefixEmailAddress prefixEmailAddress) { - switch(prefixEmailAddress) { - case PrefixEmailAddress.from: - return searchFilterByFromApplied; - case PrefixEmailAddress.to: - return searchFilterByToApplied; - default: - return false; - } - } - - String getNameContactApplied(BuildContext context, PrefixEmailAddress prefixEmailAddress) { - switch(prefixEmailAddress) { - case PrefixEmailAddress.from: - return '${AppLocalizations.of(context).from_email_address_prefix} ${from.first}'; - case PrefixEmailAddress.to: - return '${AppLocalizations.of(context).to_email_address_prefix} ${to.first}'; - default: - return ''; - } - } - - String getNameContactDefault(BuildContext context, PrefixEmailAddress prefixEmailAddress) { - switch(prefixEmailAddress) { - case PrefixEmailAddress.from: - return AppLocalizations.of(context).from_email_address_prefix; - case PrefixEmailAddress.to: - return AppLocalizations.of(context).to_email_address_prefix; - default: - return ''; - } - } - @override List get props => [ from, diff --git a/lib/features/search/email/presentation/search_email_controller.dart b/lib/features/search/email/presentation/search_email_controller.dart index 0b0d3685d6..10e35942e0 100644 --- a/lib/features/search/email/presentation/search_email_controller.dart +++ b/lib/features/search/email/presentation/search_email_controller.dart @@ -1045,6 +1045,30 @@ class SearchEmailController extends BaseController _searchEmailAction(context); } + 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 || + searchEmailFilter.value.hasKeyword.contains(KeyWordIdentifier.emailFlagged.value) || + emailSortOrderType.value != EmailSortOrderType.mostRecent; + } + + void clearAllSearchFilterApplied(BuildContext context) { + textInputSearchController.clear(); + currentSearchText.value = ''; + listRecentSearch.clear(); + listSuggestionSearch.clear(); + listResultSearch.clear(); + canSearchMore = true; + searchMoreState = SearchMoreState.idle; + emailReceiveTimeType.value = EmailReceiveTimeType.allTime; + emailSortOrderType.value = EmailSortOrderType.mostRecent; + searchEmailFilter.value = SearchEmailFilter.initial(); + _searchEmailAction(context); + } + @override void onClose() { textInputSearchFocus.removeListener(_onSearchTextInputListener); diff --git a/lib/features/search/email/presentation/search_email_view.dart b/lib/features/search/email/presentation/search_email_view.dart index 8329adea7f..a88c1e2080 100644 --- a/lib/features/search/email/presentation/search_email_view.dart +++ b/lib/features/search/email/presentation/search_email_view.dart @@ -1,6 +1,7 @@ import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/views/button/icon_button_web.dart'; +import 'package:core/presentation/views/button/tmail_button_widget.dart'; import 'package:core/presentation/views/text/text_field_builder.dart'; import 'package:core/utils/direction_utils.dart'; import 'package:core/utils/platform_info.dart'; @@ -168,45 +169,69 @@ class SearchEmailView extends GetWidget } Widget _buildListSearchFilterAction(BuildContext context) { - return Container( - height: 45, - margin: SearchEmailViewStyle.listSearchFilterButtonMargin, - alignment: AlignmentDirectional.centerStart, - child: ScrollbarListView( - scrollBehavior: ScrollConfiguration.of(context).copyWith( - dragDevices: { - PointerDeviceKind.touch, - PointerDeviceKind.mouse, - PointerDeviceKind.trackpad - }, - scrollbars: false - ), - scrollController: controller.listSearchFilterScrollController, - child: ListView( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - controller: controller.listSearchFilterScrollController, - padding: SearchEmailViewStyle.getListSearchFilterButtonPadding( - context, - controller.responsiveUtils + return Row( + children: [ + Flexible( + child: Container( + height: 45, + margin: SearchEmailViewStyle.listSearchFilterButtonMargin, + alignment: AlignmentDirectional.centerStart, + child: ScrollbarListView( + scrollBehavior: ScrollConfiguration.of(context).copyWith( + dragDevices: { + PointerDeviceKind.touch, + PointerDeviceKind.mouse, + PointerDeviceKind.trackpad + }, + scrollbars: false + ), + scrollController: controller.listSearchFilterScrollController, + child: ListView( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + controller: controller.listSearchFilterScrollController, + padding: SearchEmailViewStyle.getListSearchFilterButtonPadding( + context, + controller.responsiveUtils + ), + children: [ + _buildSearchFilterButton(context, QuickSearchFilter.folder), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.from), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.to), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.hasAttachment), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.dateTime), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.starred), + SearchEmailViewStyle.searchFilterSizeBoxMargin, + _buildSearchFilterButton(context, QuickSearchFilter.sortBy), + ], + ), + ), ), - children: [ - _buildSearchFilterButton(context, QuickSearchFilter.folder), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.from), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.to), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.hasAttachment), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.dateTime), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.starred), - SearchEmailViewStyle.searchFilterSizeBoxMargin, - _buildSearchFilterButton(context, QuickSearchFilter.sortBy), - ], ), - ), + Obx(() { + if (controller.isSearchFilterHasApplied) { + return TMailButtonWidget.fromText( + text: AppLocalizations.of(context).clearFilter, + backgroundColor: Colors.transparent, + margin: const EdgeInsetsDirectional.only(start: 8, top: 6, end: 8), + borderRadius: 10, + textStyle: const TextStyle( + color: AppColor.primaryColor, + fontSize: 13, + fontWeight: FontWeight.w500 + ), + onTapActionCallback: () => controller.clearAllSearchFilterApplied(context) + ); + } else { + return const SizedBox.shrink(); + } + }) + ], ); }