Skip to content

Commit

Permalink
TF-3002 [MOBILE] Add Clear filter button in search filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Oct 2, 2024
1 parent 46ab848 commit c387464
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<String> from;
Expand Down Expand Up @@ -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<Object?> get props => [
from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
99 changes: 62 additions & 37 deletions lib/features/search/email/presentation/search_email_view.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -168,45 +169,69 @@ class SearchEmailView extends GetWidget<SearchEmailController>
}

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();
}
})
],
);
}

Expand Down

0 comments on commit c387464

Please sign in to comment.