TF-900 fix not correct search result when close search box

This commit is contained in:
sherlock
2022-10-31 17:13:51 +07:00
committed by Dat H. Pham
parent 1b4ff83326
commit 93afb42c1b
5 changed files with 31 additions and 4 deletions
@@ -57,6 +57,7 @@ import 'package:tmail_ui_user/features/mailbox_creator/presentation/extensions/v
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_mailbox_arguments.dart'; import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_mailbox_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_email_drafts_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_email_drafts_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/action/dashboard_action.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
@@ -101,7 +102,7 @@ class MailboxController extends BaseMailboxController {
jmap.State? _currentMailboxState; jmap.State? _currentMailboxState;
List<String> listMailboxNameAsStringExist = <String>[]; List<String> listMailboxNameAsStringExist = <String>[];
late Worker accountIdWorker, viewStateWorker; late Worker accountIdWorker, viewStateWorker, dashboardActionWorker;
MailboxController( MailboxController(
this._getAllMailboxInteractor, this._getAllMailboxInteractor,
@@ -236,6 +237,14 @@ class MailboxController extends BaseMailboxController {
}); });
} }
}); });
dashboardActionWorker = ever(mailboxDashBoardController.dashBoardAction, (action) {
if(action is DashBoardAction) {
if(action is ClearSearchEmailAction) {
_switchBackToMailboxDefault();
}
}
});
} }
void _registerSearchFocusListener() { void _registerSearchFocusListener() {
@@ -252,6 +261,7 @@ class MailboxController extends BaseMailboxController {
void _clearWorker() { void _clearWorker() {
accountIdWorker.call(); accountIdWorker.call();
viewStateWorker.call(); viewStateWorker.call();
dashboardActionWorker.call();
} }
void _initCollapseMailboxCategories() { void _initCollapseMailboxCategories() {
@@ -97,3 +97,10 @@ class EmptyTrashAction extends DashBoardAction {
@override @override
List<Object?> get props => []; List<Object?> get props => [];
} }
class ClearSearchEmailAction extends DashBoardAction {
ClearSearchEmailAction();
@override
List<Object?> get props => [];
}
@@ -422,6 +422,11 @@ class MailboxDashBoardController extends ReloadableController {
&& dashboardRoute.value == DashboardRoutes.emailDetailed; && dashboardRoute.value == DashboardRoutes.emailDetailed;
} }
void clearSearchEmail() {
dispatchAction(ClearSearchEmailAction());
searchController.disableSearch();
}
void _unSelectedMailbox() { void _unSelectedMailbox() {
selectedMailbox.value = null; selectedMailbox.value = null;
} }
@@ -157,7 +157,6 @@ class SearchController extends BaseController {
searchInputController.clear(); searchInputController.clear();
cleanSearchFilter(); cleanSearchFilter();
searchFocus.unfocus(); searchFocus.unfocus();
searchState.value = searchState.value.disableSearchState();
} }
}); });
} }
@@ -17,12 +17,11 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/re
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class SearchInputFormWidget extends StatelessWidget with AppLoaderMixin { class SearchInputFormWidget extends StatelessWidget with AppLoaderMixin {
final MailboxDashBoardController dashBoardController; final MailboxDashBoardController dashBoardController;
final ImagePaths imagePaths; final ImagePaths imagePaths;
final double maxWidth; final double maxWidth;
const SearchInputFormWidget({ SearchInputFormWidget({
Key? key, Key? key,
required this.dashBoardController, required this.dashBoardController,
required this.imagePaths, required this.imagePaths,
@@ -65,6 +64,8 @@ class SearchInputFormWidget extends StatelessWidget with AppLoaderMixin {
if (query.isNotEmpty) { if (query.isNotEmpty) {
controller.saveRecentSearch(RecentSearch.now(query)); controller.saveRecentSearch(RecentSearch.now(query));
dashBoardController.searchEmail(context, query); dashBoardController.searchEmail(context, query);
} else {
dashBoardController.clearSearchEmail();
} }
}, },
onChanged: controller.onChangeTextSearch, onChanged: controller.onChangeTextSearch,
@@ -92,6 +93,8 @@ class SearchInputFormWidget extends StatelessWidget with AppLoaderMixin {
if (keyword.isNotEmpty) { if (keyword.isNotEmpty) {
controller.saveRecentSearch(RecentSearch.now(keyword)); controller.saveRecentSearch(RecentSearch.now(keyword));
dashBoardController.searchEmail(context, keyword); dashBoardController.searchEmail(context, keyword);
} else {
dashBoardController.clearSearchEmail();
} }
}), }),
clearTextButton: buildIconWeb( clearTextButton: buildIconWeb(
@@ -150,7 +153,10 @@ class SearchInputFormWidget extends StatelessWidget with AppLoaderMixin {
if (query.isNotEmpty) { if (query.isNotEmpty) {
controller.saveRecentSearch(RecentSearch.now(query)); controller.saveRecentSearch(RecentSearch.now(query));
dashBoardController.searchEmail(context, query); dashBoardController.searchEmail(context, query);
} else {
dashBoardController.clearSearchEmail();
} }
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),