TF-1477 Improve UX for advanced and quick search
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ enum AdvancedSearchFilterField {
|
||||
case AdvancedSearchFilterField.notKeyword:
|
||||
return AppLocalizations.of(context).enterSearchTerm;
|
||||
case AdvancedSearchFilterField.mailBox:
|
||||
return AppLocalizations.of(context).allMails;
|
||||
return AppLocalizations.of(context).allMailboxes;
|
||||
case AdvancedSearchFilterField.date:
|
||||
return AppLocalizations.of(context).allTime;
|
||||
case AdvancedSearchFilterField.hasAttachment:
|
||||
|
||||
+43
-4
@@ -37,10 +37,8 @@ enum EmailReceiveTimeType {
|
||||
}
|
||||
}
|
||||
|
||||
UTCDate? toUTCDate() {
|
||||
UTCDate? toOldestUTCDate() {
|
||||
switch(this) {
|
||||
case EmailReceiveTimeType.allTime:
|
||||
return null;
|
||||
case EmailReceiveTimeType.last7Days:
|
||||
final today = DateTime.now();
|
||||
final last7Days = today.subtract(const Duration(days: 7));
|
||||
@@ -57,8 +55,49 @@ enum EmailReceiveTimeType {
|
||||
final today = DateTime.now();
|
||||
final lastYear = DateTime(today.year - 1, today.month, today.day);
|
||||
return lastYear.toUTCDate();
|
||||
case EmailReceiveTimeType.customRange:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
UTCDate? toLatestUTCDate() {
|
||||
switch(this) {
|
||||
case EmailReceiveTimeType.last7Days:
|
||||
case EmailReceiveTimeType.last30Days:
|
||||
case EmailReceiveTimeType.last6Months:
|
||||
case EmailReceiveTimeType.lastYear:
|
||||
return DateTime.now().toUTCDate();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
UTCDate? getAfterDate(UTCDate? startDate) {
|
||||
if (startDate != null) {
|
||||
return startDate;
|
||||
} else {
|
||||
return toOldestUTCDate();
|
||||
}
|
||||
}
|
||||
|
||||
UTCDate? getBeforeDate(UTCDate? endDate, UTCDate? loadMoreDate) {
|
||||
if (endDate != null) {
|
||||
if (loadMoreDate != null && loadMoreDate.value.isBefore(endDate.value)) {
|
||||
return loadMoreDate;
|
||||
} else {
|
||||
return endDate;
|
||||
}
|
||||
} else {
|
||||
final latestDate = toLatestUTCDate();
|
||||
if (latestDate != null) {
|
||||
if (loadMoreDate != null && loadMoreDate.value.isBefore(latestDate.value)) {
|
||||
return loadMoreDate;
|
||||
} else {
|
||||
return latestDate;
|
||||
}
|
||||
} else {
|
||||
return loadMoreDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:model/user/user_profile.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/search_email_filter.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
enum QuickSearchFilter {
|
||||
@@ -9,22 +12,36 @@ enum QuickSearchFilter {
|
||||
last7Days,
|
||||
fromMe;
|
||||
|
||||
String getTitle(BuildContext context, {EmailReceiveTimeType? receiveTimeType}) {
|
||||
String getName(BuildContext context) {
|
||||
switch(this) {
|
||||
case QuickSearchFilter.hasAttachment:
|
||||
return AppLocalizations.of(context).hasAttachment;
|
||||
case QuickSearchFilter.last7Days:
|
||||
if (receiveTimeType != null) {
|
||||
return receiveTimeType.getTitle(context);
|
||||
}
|
||||
return AppLocalizations.of(context).last7Days;
|
||||
case QuickSearchFilter.fromMe:
|
||||
return AppLocalizations.of(context).fromMe;
|
||||
}
|
||||
}
|
||||
|
||||
String getIcon(ImagePaths imagePaths, {required bool quickSearchFilterSelected}) {
|
||||
if (quickSearchFilterSelected) {
|
||||
String getTitle(
|
||||
BuildContext context, {
|
||||
EmailReceiveTimeType? receiveTimeType,
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
}) {
|
||||
switch(this) {
|
||||
case QuickSearchFilter.hasAttachment:
|
||||
return AppLocalizations.of(context).hasAttachment;
|
||||
case QuickSearchFilter.last7Days:
|
||||
return receiveTimeType?.getTitle(context, startDate: startDate, endDate: endDate)
|
||||
?? AppLocalizations.of(context).allTime;
|
||||
case QuickSearchFilter.fromMe:
|
||||
return AppLocalizations.of(context).fromMe;
|
||||
}
|
||||
}
|
||||
|
||||
String getIcon(ImagePaths imagePaths, {required bool isFilterSelected}) {
|
||||
if (isFilterSelected) {
|
||||
return imagePaths.icSelectedSB;
|
||||
} else {
|
||||
switch(this) {
|
||||
@@ -38,16 +55,16 @@ enum QuickSearchFilter {
|
||||
}
|
||||
}
|
||||
|
||||
Color getBackgroundColor({required bool quickSearchFilterSelected}) {
|
||||
if (quickSearchFilterSelected) {
|
||||
Color getBackgroundColor({required bool isFilterSelected}) {
|
||||
if (isFilterSelected) {
|
||||
return AppColor.colorItemEmailSelectedDesktop;
|
||||
} else {
|
||||
return AppColor.colorButtonHeaderThread;
|
||||
}
|
||||
}
|
||||
|
||||
TextStyle getTextStyle({required bool quickSearchFilterSelected}) {
|
||||
if (quickSearchFilterSelected) {
|
||||
TextStyle getTextStyle({required bool isFilterSelected}) {
|
||||
if (isFilterSelected) {
|
||||
return const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -59,4 +76,19 @@ enum QuickSearchFilter {
|
||||
color: AppColor.colorTextButtonHeaderThread);
|
||||
}
|
||||
}
|
||||
|
||||
bool isApplied(List<QuickSearchFilter> listFilter) => listFilter.contains(this);
|
||||
|
||||
bool isSelected(SearchEmailFilter filter, UserProfile? userProfile) {
|
||||
switch (this) {
|
||||
case QuickSearchFilter.hasAttachment:
|
||||
return filter.hasAttachment == true;
|
||||
case QuickSearchFilter.last7Days:
|
||||
return true;
|
||||
case QuickSearchFilter.fromMe:
|
||||
return userProfile != null &&
|
||||
filter.from.contains(userProfile.email) &&
|
||||
filter.from.length == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import 'package:jmap_dart_client/jmap/core/filter/filter_operator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/filter/operator/logic_filter_operator.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_filter_condition.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:model/extensions/email_filter_condition_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
|
||||
|
||||
@@ -52,9 +53,9 @@ class SearchEmailFilter with EquatableMixin {
|
||||
PresentationMailbox? mailbox,
|
||||
EmailReceiveTimeType? emailReceiveTimeType,
|
||||
bool? hasAttachment,
|
||||
UTCDate? before,
|
||||
UTCDate? startDate,
|
||||
UTCDate? endDate,
|
||||
Option<UTCDate>? beforeOption,
|
||||
Option<UTCDate>? startDateOption,
|
||||
Option<UTCDate>? endDateOption,
|
||||
}) {
|
||||
return SearchEmailFilter(
|
||||
from: from ?? this.from,
|
||||
@@ -65,9 +66,9 @@ class SearchEmailFilter with EquatableMixin {
|
||||
mailbox: mailbox ?? this.mailbox,
|
||||
emailReceiveTimeType: emailReceiveTimeType ?? this.emailReceiveTimeType,
|
||||
hasAttachment: hasAttachment ?? this.hasAttachment,
|
||||
before: before ?? this.before,
|
||||
startDate: startDate ?? this.startDate,
|
||||
endDate: endDate ?? this.endDate,
|
||||
before: _getOptionParam(beforeOption, before),
|
||||
startDate: _getOptionParam(startDateOption, startDate),
|
||||
endDate: _getOptionParam(endDateOption, endDate),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,17 +85,13 @@ class SearchEmailFilter with EquatableMixin {
|
||||
text: text?.value.trim().isNotEmpty == true
|
||||
? text?.value
|
||||
: null,
|
||||
inMailbox: mailbox == PresentationMailbox.unifiedMailbox
|
||||
? null
|
||||
: mailbox?.id,
|
||||
after: emailReceiveTimeType == EmailReceiveTimeType.customRange
|
||||
? startDate
|
||||
: emailReceiveTimeType.toUTCDate(),
|
||||
inMailbox: mailbox?.mailboxId,
|
||||
after: emailReceiveTimeType.getAfterDate(startDate),
|
||||
hasAttachment: hasAttachment == false ? null : hasAttachment,
|
||||
subject: subject,
|
||||
before: emailReceiveTimeType == EmailReceiveTimeType.customRange
|
||||
? endDate
|
||||
: before,
|
||||
subject: subject?.trim().isNotEmpty == true
|
||||
? subject
|
||||
: null,
|
||||
before: emailReceiveTimeType.getBeforeDate(endDate, before)
|
||||
);
|
||||
|
||||
final listEmailCondition = {
|
||||
@@ -135,39 +132,4 @@ class SearchEmailFilter with EquatableMixin {
|
||||
startDate,
|
||||
endDate
|
||||
];
|
||||
}
|
||||
|
||||
extension SearchEmailFilterExtension on SearchEmailFilter {
|
||||
|
||||
SearchEmailFilter clearBeforeDate() {
|
||||
return SearchEmailFilter(
|
||||
from: from,
|
||||
to: to,
|
||||
text: text,
|
||||
subject: subject,
|
||||
notKeyword: notKeyword,
|
||||
mailbox: mailbox,
|
||||
emailReceiveTimeType: emailReceiveTimeType,
|
||||
hasAttachment: hasAttachment,
|
||||
before: null,
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
);
|
||||
}
|
||||
|
||||
SearchEmailFilter withDateRange({UTCDate? startDate, UTCDate? endDate}) {
|
||||
return SearchEmailFilter(
|
||||
from: from,
|
||||
to: to,
|
||||
text: text,
|
||||
subject: subject,
|
||||
notKeyword: notKeyword,
|
||||
mailbox: mailbox,
|
||||
emailReceiveTimeType: emailReceiveTimeType,
|
||||
hasAttachment: hasAttachment,
|
||||
before: before,
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user