From 3be8750baec3b651261e379a15e656bcdc7a8ae9 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 17 Jan 2025 19:04:13 +0700 Subject: [PATCH] TF-3345 Fix sort order blinks when deleting emails in search --- .../model/search/search_email_filter.dart | 8 ++------ .../presentation/search_email_controller.dart | 17 ++++++++++------- .../thread/presentation/thread_controller.dart | 14 ++++++++------ 3 files changed, 20 insertions(+), 19 deletions(-) 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 cb6b3f5628..e29bcf653c 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 @@ -99,16 +99,12 @@ class SearchEmailFilter with EquatableMixin, OptionParamMixin { ? text?.value.trim() : null, inMailbox: mailbox?.mailboxId, - after: sortOrderType.isScrollByPosition() - ? null - : emailReceiveTimeType.getAfterDate(startDate), + after: emailReceiveTimeType.getAfterDate(startDate), hasAttachment: !hasAttachment ? null : hasAttachment, subject: subject?.trim().isNotEmpty == true ? subject?.trim() : null, - before: sortOrderType.isScrollByPosition() - ? null - : emailReceiveTimeType.getBeforeDate(endDate, before), + before: emailReceiveTimeType.getBeforeDate(endDate, before), from: from.length == 1 ? from.first : null, diff --git a/lib/features/search/email/presentation/search_email_controller.dart b/lib/features/search/email/presentation/search_email_controller.dart index e92905595f..6bd997332c 100644 --- a/lib/features/search/email/presentation/search_email_controller.dart +++ b/lib/features/search/email/presentation/search_email_controller.dart @@ -215,7 +215,9 @@ class SearchEmailController extends BaseController currentSearchText.value = value; _updateSimpleSearchFilter( textOption: option(value.isNotEmpty, SearchQuery(value)), - beforeOption: const None(), + beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition() + ? const None() + : null, positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0) ); if (value.isNotEmpty && session != null && accountId != null) { @@ -319,7 +321,9 @@ class SearchEmailController extends BaseController : ThreadConstants.defaultLimit; _updateSimpleSearchFilter( - beforeOption: const None(), + beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition() + ? const None() + : null, positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0), ); @@ -435,7 +439,9 @@ class SearchEmailController extends BaseController _updateSimpleSearchFilter( positionOption: option(searchEmailFilter.value.sortOrderType.isScrollByPosition(), 0), - beforeOption: const None(), + beforeOption: !searchEmailFilter.value.sortOrderType.isScrollByPosition() + ? const None() + : null, ); consumeState(_searchEmailInteractor.execute( @@ -484,10 +490,7 @@ class SearchEmailController extends BaseController final lastEmail = listResultSearch.last; if (searchEmailFilter.value.sortOrderType.isScrollByPosition()) { - _updateSimpleSearchFilter( - positionOption: Some(listResultSearch.length), - beforeOption: const None() - ); + _updateSimpleSearchFilter(positionOption: Some(listResultSearch.length)); } else if (searchEmailFilter.value.sortOrderType == EmailSortOrderType.oldest) { _updateSimpleSearchFilter(startDateOption: optionOf(lastEmail.receivedAt)); } else { diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 03d8d4da57..0fcc9b912c 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -666,7 +666,9 @@ class ThreadController extends BaseController with EmailActionController { _searchEmailFilter.sortOrderType.isScrollByPosition(), 0, ), - beforeOption: const None(), + beforeOption: !_searchEmailFilter.sortOrderType.isScrollByPosition() + ? const None() + : null, ); final searchViewState = await _searchEmailInteractor.execute( _session!, @@ -949,7 +951,10 @@ class ThreadController extends BaseController with EmailActionController { searchController.updateFilterEmail( positionOption: option(_searchEmailFilter.sortOrderType.isScrollByPosition(), 0), - beforeOption: const None()); + beforeOption: !_searchEmailFilter.sortOrderType.isScrollByPosition() + ? const None() + : null, + ); searchController.activateSimpleSearch(); @@ -1023,10 +1028,7 @@ class ThreadController extends BaseController with EmailActionController { if (_searchEmailFilter.sortOrderType.isScrollByPosition()) { final nextPosition = mailboxDashBoardController.emailsInCurrentMailbox.length; log('ThreadController::_searchMoreEmails:nextPosition: $nextPosition'); - searchController.updateFilterEmail( - positionOption: Some(nextPosition), - beforeOption: const None() - ); + searchController.updateFilterEmail(positionOption: Some(nextPosition)); } else if (_searchEmailFilter.sortOrderType == EmailSortOrderType.oldest) { searchController.updateFilterEmail(startDateOption: optionOf(lastEmail?.receivedAt)); } else {