From 9ba62bbb5160ab48c2d475ef19bdcb51a761c217 Mon Sep 17 00:00:00 2001 From: Julian KOUNE Date: Wed, 1 Sep 2021 12:29:17 +0200 Subject: [PATCH] search upload request inside presentation layer (#523) (cherry picked from commit 0b13444ceb771cf233c6d4575f81240b6c14f063) --- lib/l10n/intl_en.arb | 6 ++ lib/l10n/intl_fr.arb | 6 ++ lib/l10n/intl_messages.arb | 8 +- lib/l10n/intl_ru.arb | 6 ++ lib/l10n/intl_vi.arb | 6 ++ lib/presentation/di/module/widget_module.dart | 1 + .../localizations/app_localizations.dart | 6 ++ .../actions/upload_request_inside_action.dart | 12 +++ .../upload_request_inside_reducer.dart | 4 + lib/presentation/redux/states/ui_state.dart | 5 +- .../states/upload_request_inside_state.dart | 48 ++++++++++-- .../home_app_bar/home_app_bar_viewmodel.dart | 12 +++ .../home_app_bar/home_app_bar_widget.dart | 2 + .../widget/home/home_viewmodel.dart | 13 +++- ...reated_upload_request_group_viewmodel.dart | 10 +-- .../upload_request_inside_viewmodel.dart | 64 +++++++++++++++- .../upload_request_inside_widget.dart | 74 +++++++++++++++---- 17 files changed, 246 insertions(+), 37 deletions(-) diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index a3f5d2a82..6b43a1fe1 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1751,5 +1751,11 @@ "numberOfItems": {}, "singleItemName": {} } + }, + "search_in_upload_request_entries": "Search in Upload Requests Entries", + "@search_in_upload_request_entries": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index eb1bae66b..0648406c6 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -1751,5 +1751,11 @@ "numberOfItems": {}, "singleItemName": {} } + }, + "search_in_upload_request_entries": "Search in Upload Requests Entries", + "@search_in_upload_request_entries": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index 4f61ca165..ee10f7293 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,5 +1,5 @@ { - "@@last_modified": "2021-08-26T17:27:34.221951", + "@@last_modified": "2021-09-01T12:26:19.414501", "initializing_data": "Initializing data...", "@initializing_data": { "type": "text", @@ -2239,5 +2239,11 @@ "numberOfItems": {}, "singleItemName": {} } + }, + "search_in_upload_request_entries": "Search in Upload Requests Entries", + "@search_in_upload_request_entries": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 0dda724f4..98e2da23b 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -1751,5 +1751,11 @@ "numberOfItems": {}, "singleItemName": {} } + }, + "search_in_upload_request_entries": "Search in Upload Requests Entries", + "@search_in_upload_request_entries": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/l10n/intl_vi.arb b/lib/l10n/intl_vi.arb index f64580a00..ee56e6d1d 100644 --- a/lib/l10n/intl_vi.arb +++ b/lib/l10n/intl_vi.arb @@ -1751,5 +1751,11 @@ "numberOfItems": {}, "singleItemName": {} } + }, + "search_in_upload_request_entries": "Search in Upload Requests Entries", + "@search_in_upload_request_entries": { + "type": "text", + "placeholders_order": [], + "placeholders": {} } } \ No newline at end of file diff --git a/lib/presentation/di/module/widget_module.dart b/lib/presentation/di/module/widget_module.dart index 44ca6dd59..31af19b3b 100644 --- a/lib/presentation/di/module/widget_module.dart +++ b/lib/presentation/di/module/widget_module.dart @@ -492,6 +492,7 @@ class WidgetModule { getIt.get(), getIt(), getIt(), + getIt() )); } diff --git a/lib/presentation/localizations/app_localizations.dart b/lib/presentation/localizations/app_localizations.dart index 20a0c6aaf..aa63c2bed 100644 --- a/lib/presentation/localizations/app_localizations.dart +++ b/lib/presentation/localizations/app_localizations.dart @@ -2160,6 +2160,12 @@ class AppLocalizations { ); } + String get search_in_upload_request_entries { + return Intl.message( + 'Search in Upload Requests Entries', + name: 'search_in_upload_request_entries', + ); + } } class AppLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/presentation/redux/actions/upload_request_inside_action.dart b/lib/presentation/redux/actions/upload_request_inside_action.dart index 0b1fddd82..fb833d4e6 100644 --- a/lib/presentation/redux/actions/upload_request_inside_action.dart +++ b/lib/presentation/redux/actions/upload_request_inside_action.dart @@ -105,3 +105,15 @@ class UploadRequestSelectAllEntryAction extends ActionOffline { class UploadRequestUnSelectAllEntryAction extends ActionOffline { UploadRequestUnSelectAllEntryAction(); } + +@immutable +class UploadRequestEntrySetSearchResultAction extends ActionOffline { + final List uploadRequestEntries; + + UploadRequestEntrySetSearchResultAction(this.uploadRequestEntries); +} + +@immutable +class CleanUploadRequestInsideAction extends ActionOffline { + CleanUploadRequestInsideAction(); +} diff --git a/lib/presentation/redux/reducers/upload_request_inside_reducer.dart b/lib/presentation/redux/reducers/upload_request_inside_reducer.dart index c57aa9b16..26434714d 100644 --- a/lib/presentation/redux/reducers/upload_request_inside_reducer.dart +++ b/lib/presentation/redux/reducers/upload_request_inside_reducer.dart @@ -37,6 +37,7 @@ import 'package:redux/redux.dart'; final uploadRequestInsideReducer = combineReducers([ TypedReducer((UploadRequestInsideState state, _) => state.startLoadingState()), + TypedReducer((UploadRequestInsideState state, UploadRequestInsideAction action) => state.sendViewState(viewState: action.viewState)), TypedReducer((UploadRequestInsideState state, SetUploadRequestsArgumentsAction action) => state.setUploadRequestArgument(newUploadRequestArguments: action.arguments)), TypedReducer((UploadRequestInsideState state, GetAllUploadRequestsAction action) => @@ -67,4 +68,7 @@ final uploadRequestInsideReducer = combineReducers([ state.selectAllUploadRequestEntry()), TypedReducer((UploadRequestInsideState state, UploadRequestUnSelectAllEntryAction action) => state.unSelectAllUploadRequestEntry()), + TypedReducer((UploadRequestInsideState state, UploadRequestEntrySetSearchResultAction action) => + state.setSearchResult(newSearchResult: action.uploadRequestEntries)), + TypedReducer((UploadRequestInsideState state, _) => state.clearViewState()), ]); diff --git a/lib/presentation/redux/states/ui_state.dart b/lib/presentation/redux/states/ui_state.dart index 600921339..cbee25b93 100644 --- a/lib/presentation/redux/states/ui_state.dart +++ b/lib/presentation/redux/states/ui_state.dart @@ -65,7 +65,7 @@ class UIState with EquatableMixin { } UIState setSearchState(SearchState searchState) { - return UIState(routePath, searchState, uploadRequestGroupTabIndex: uploadRequestGroupTabIndex, selectedSharedSpace: selectedSharedSpace); + return UIState(routePath, searchState, uploadRequestGroupTabIndex: uploadRequestGroupTabIndex, selectedSharedSpace: selectedSharedSpace, uploadRequestGroup: uploadRequestGroup); } UIState setUploadRequestGroupIndexTab(int newIndex) { @@ -112,5 +112,6 @@ enum SearchDestination { sharedSpace, allSharedSpaces, receivedShares, - uploadRequestGroups + uploadRequestGroups, + uploadRequestInside } diff --git a/lib/presentation/redux/states/upload_request_inside_state.dart b/lib/presentation/redux/states/upload_request_inside_state.dart index 81fa7d561..fa61bdf2b 100644 --- a/lib/presentation/redux/states/upload_request_inside_state.dart +++ b/lib/presentation/redux/states/upload_request_inside_state.dart @@ -68,14 +68,28 @@ class UploadRequestInsideState extends LinShareState with EquatableMixin { @override UploadRequestInsideState clearViewState() { - return UploadRequestInsideState(Right(IdleState()), uploadRequests, uploadRequestEntries, selectMode, uploadRequestDocumentType, - uploadRequestGroup, selectedUploadRequest); + return UploadRequestInsideState( + Right(IdleState()), + uploadRequests, + uploadRequestEntries, + selectMode, + uploadRequestDocumentType, + uploadRequestGroup, + selectedUploadRequest + ); } @override UploadRequestInsideState sendViewState({required Either viewState}) { return UploadRequestInsideState( - viewState, uploadRequests, uploadRequestEntries, selectMode, uploadRequestDocumentType, null, null); + viewState, + uploadRequests, + uploadRequestEntries, + selectMode, + uploadRequestDocumentType, + uploadRequestGroup, + selectedUploadRequest + ); } UploadRequestInsideState setUploadRequestArgument({required UploadRequestArguments newUploadRequestArguments}) { @@ -132,12 +146,12 @@ class UploadRequestInsideState extends LinShareState with EquatableMixin { UploadRequestInsideState selectUploadRequestEntry(SelectableElement selectedUploadRequestEntry) { uploadRequestEntries.firstWhere((entry) => entry == selectedUploadRequestEntry).toggleSelect(); return UploadRequestInsideState( - viewState, - uploadRequests, - uploadRequestEntries, + viewState, + uploadRequests, + uploadRequestEntries, SelectMode.ACTIVE, - uploadRequestDocumentType, - uploadRequestGroup, + uploadRequestDocumentType, + uploadRequestGroup, selectedUploadRequest); } @@ -183,6 +197,24 @@ class UploadRequestInsideState extends LinShareState with EquatableMixin { ); } + UploadRequestInsideState setSearchResult({required List newSearchResult}) { + final selectedElements = uploadRequestEntries + .where((element) => element.selectMode == SelectMode.ACTIVE) + .map((element) => element.element) + .toList(); + return UploadRequestInsideState( + viewState, + uploadRequests, + newSearchResult.map((entry) => selectedElements.contains(entry) + ? SelectableElement(entry, SelectMode.ACTIVE) + : SelectableElement(entry, SelectMode.INACTIVE)).toList(), + selectMode, + uploadRequestDocumentType, + uploadRequestGroup, + selectedUploadRequest + ); + } + @override List get props => [...super.props, diff --git a/lib/presentation/widget/home/home_app_bar/home_app_bar_viewmodel.dart b/lib/presentation/widget/home/home_app_bar/home_app_bar_viewmodel.dart index 5b0e387bc..36472e97b 100644 --- a/lib/presentation/widget/home/home_app_bar/home_app_bar_viewmodel.dart +++ b/lib/presentation/widget/home/home_app_bar/home_app_bar_viewmodel.dart @@ -41,6 +41,7 @@ import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_g import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_active_closed_action.dart'; import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_archived_action.dart'; import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_created_action.dart'; +import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_inside_action.dart'; import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart'; import 'package:linshare_flutter_app/presentation/widget/base/base_viewmodel.dart'; import 'package:redux/redux.dart'; @@ -56,6 +57,7 @@ class HomeAppBarViewModel extends BaseViewModel { _handleReceivedShareViewState(_typeAheadController, event.receivedShareState.viewState); _handleSharedSpaceViewState(_typeAheadController, event.sharedSpaceState.viewState); _handleUploadRequestGroupsViewState(_typeAheadController, event.uploadRequestGroupState.viewState); + _handleUploadRequestInsideViewState(_typeAheadController, event.uploadRequestInsideState.viewState); }); } @@ -102,6 +104,16 @@ class HomeAppBarViewModel extends BaseViewModel { }); } + void _handleUploadRequestInsideViewState( + TextEditingController _typeAheadController, Either viewState) { + viewState.fold((failure) => null, (success) { + if (success is DisableSearchViewState) { + _typeAheadController.clear(); + store.dispatch(CleanUploadRequestInsideAction()); + } + }); + } + @override void onDisposed() { _streamSubscription.cancel(); diff --git a/lib/presentation/widget/home/home_app_bar/home_app_bar_widget.dart b/lib/presentation/widget/home/home_app_bar/home_app_bar_widget.dart index de98fcc87..378cdc1d3 100644 --- a/lib/presentation/widget/home/home_app_bar/home_app_bar_widget.dart +++ b/lib/presentation/widget/home/home_app_bar/home_app_bar_widget.dart @@ -226,6 +226,8 @@ class _HomeAppBarWidgetState extends State { return AppLocalizations.of(context).search_in_my_received_shares; case SearchDestination.uploadRequestGroups: return AppLocalizations.of(context).search_in_upload_request_groups; + case SearchDestination.uploadRequestInside: + return AppLocalizations.of(context).search_in_upload_request_entries; default: return ''; } diff --git a/lib/presentation/widget/home/home_viewmodel.dart b/lib/presentation/widget/home/home_viewmodel.dart index 2375cc5bd..c62a85a42 100644 --- a/lib/presentation/widget/home/home_viewmodel.dart +++ b/lib/presentation/widget/home/home_viewmodel.dart @@ -45,6 +45,7 @@ import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_g import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_active_closed_action.dart'; import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_archived_action.dart'; import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_group_created_action.dart'; +import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_inside_action.dart'; import 'package:linshare_flutter_app/presentation/redux/online_thunk_action.dart'; import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart'; import 'package:linshare_flutter_app/presentation/redux/states/ui_state.dart'; @@ -158,9 +159,12 @@ class HomeViewModel extends BaseViewModel { } else if (store.state.uiState.searchState.searchDestination == SearchDestination.uploadRequestGroups) { store.dispatch(UploadRequestGroupAction(Right(DisableSearchViewState()))); store.dispatch(CleanUploadRequestGroupAction()); - store.dispatch(CleanCreatedUploadRequestGroupAction()); - store.dispatch(CleanArchivedUploadRequestGroupAction()); - store.dispatch(CleanActiveClosedUploadRequestGroupAction()); + store.dispatch(CleanCreatedUploadRequestGroupAction()); + store.dispatch(CleanArchivedUploadRequestGroupAction()); + store.dispatch(CleanActiveClosedUploadRequestGroupAction()); + } else if (store.state.uiState.searchState.searchDestination == SearchDestination.uploadRequestInside) { + store.dispatch(UploadRequestInsideAction(Right(DisableSearchViewState()))); + store.dispatch(CleanUploadRequestInsideAction()); } } @@ -183,6 +187,9 @@ class HomeViewModel extends BaseViewModel { store.dispatch(CleanCreatedUploadRequestGroupAction()); store.dispatch(CleanArchivedUploadRequestGroupAction()); store.dispatch(CleanActiveClosedUploadRequestGroupAction()); + } else if (store.state.uiState.searchState.searchDestination == SearchDestination.uploadRequestInside) { + store.dispatch(UploadRequestInsideAction(Right(SearchUploadRequestEntriesNewQuery(SearchQuery(text.trim()))))); + store.dispatch(CleanUploadRequestInsideAction()); } } diff --git a/lib/presentation/widget/upload_request_group/created/created_upload_request_group_viewmodel.dart b/lib/presentation/widget/upload_request_group/created/created_upload_request_group_viewmodel.dart index 4268503e1..3b57022a2 100644 --- a/lib/presentation/widget/upload_request_group/created/created_upload_request_group_viewmodel.dart +++ b/lib/presentation/widget/upload_request_group/created/created_upload_request_group_viewmodel.dart @@ -58,12 +58,12 @@ class CreatedUploadRequestGroupViewModel extends UploadRequestGroupTabViewModel SearchQuery get searchQuery => _searchQuery; CreatedUploadRequestGroupViewModel( - Store store, - this._appNavigation, - this._getAllUploadRequestGroupsInteractor, + Store store, + this._appNavigation, + this._getAllUploadRequestGroupsInteractor, this._getSorterInteractor, - this._saveSorterInteractor, - this._sortInteractor, + this._saveSorterInteractor, + this._sortInteractor, this._searchUploadRequestGroupsInteractor, this._multipleUploadRequestGroupStateInteractor) : super( store, diff --git a/lib/presentation/widget/upload_request_inside/upload_request_inside_viewmodel.dart b/lib/presentation/widget/upload_request_inside/upload_request_inside_viewmodel.dart index 0ac5fb1ff..ae67bc5bd 100644 --- a/lib/presentation/widget/upload_request_inside/upload_request_inside_viewmodel.dart +++ b/lib/presentation/widget/upload_request_inside/upload_request_inside_viewmodel.dart @@ -29,6 +29,8 @@ // 3 and for // the Additional Terms applicable to LinShare software. +import 'dart:async'; + import 'package:dartz/dartz.dart'; import 'package:domain/domain.dart'; import 'package:flutter/cupertino.dart'; @@ -38,9 +40,11 @@ import 'package:linshare_flutter_app/presentation/model/file/presentation_file.d import 'package:linshare_flutter_app/presentation/model/file/selectable_element.dart'; import 'package:linshare_flutter_app/presentation/model/file/upload_request_entry_presentation_file.dart'; import 'package:linshare_flutter_app/presentation/model/item_selection_type.dart'; +import 'package:linshare_flutter_app/presentation/redux/actions/ui_action.dart'; import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_inside_action.dart'; import 'package:linshare_flutter_app/presentation/redux/online_thunk_action.dart'; import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart'; +import 'package:linshare_flutter_app/presentation/redux/states/ui_state.dart'; import 'package:linshare_flutter_app/presentation/redux/states/upload_request_inside_state.dart'; import 'package:linshare_flutter_app/presentation/util/router/app_navigation.dart'; import 'package:linshare_flutter_app/presentation/view/context_menu/context_menu_builder.dart'; @@ -63,6 +67,12 @@ class UploadRequestInsideViewModel extends BaseViewModel { late UploadRequestArguments _arguments; final DownloadUploadRequestEntriesInteractor _downloadEntriesInteractor; final DownloadMultipleUploadRequestEntryIOSInteractor _downloadMultipleEntryIOSInteractor; + final SearchUploadRequestEntriesInteractor _searchUploadRequestEntriesInteractor; + late StreamSubscription _storeStreamSubscription; + + SearchQuery _searchQuery = SearchQuery(''); + SearchQuery get searchQuery => _searchQuery; + List _uploadRequestEntriesList = []; UploadRequestInsideViewModel( Store store, @@ -71,7 +81,19 @@ class UploadRequestInsideViewModel extends BaseViewModel { this._getAllUploadRequestEntriesInteractor, this._downloadEntriesInteractor, this._downloadMultipleEntryIOSInteractor, - ) : super(store); + this._searchUploadRequestEntriesInteractor + ) : super(store) { + _storeStreamSubscription = store.onChange.listen((event) { + event.uploadRequestInsideState.viewState.fold((failure) => null, (success) { + if (success is SearchUploadRequestEntriesNewQuery && event.uiState.searchState.searchStatus == SearchStatus.ACTIVE) { + _search(success.searchQuery); + } else if (success is DisableSearchViewState) { + store.dispatch((UploadRequestEntrySetSearchResultAction(_uploadRequestEntriesList))); + _searchQuery = SearchQuery(''); + } + }); + }); + } void initState(UploadRequestArguments arguments) { _arguments = arguments; @@ -135,12 +157,14 @@ class UploadRequestInsideViewModel extends BaseViewModel { await _getAllUploadRequestEntriesInteractor.execute(uploadRequest.uploadRequestId).then( (result) => result.fold( (failure) { - if(failure is UploadRequestEntryFailure) { + _uploadRequestEntriesList = []; + if (failure is UploadRequestEntryFailure) { _handleFailedAction(failure); } }, (success) { - if(success is UploadRequestEntryViewState) { + _uploadRequestEntriesList = success is UploadRequestEntryViewState ? success.uploadRequestEntries : []; + if (success is UploadRequestEntryViewState) { store.dispatch(GetAllUploadRequestEntriesAction(Right(success))); } }) @@ -328,8 +352,42 @@ class UploadRequestInsideViewModel extends BaseViewModel { }; } + // Search + void openSearchState() { + store.dispatch(EnableSearchStateAction(SearchDestination.uploadRequestInside)); + store.dispatch((UploadRequestEntrySetSearchResultAction([]))); + } + + void _search(SearchQuery searchQuery) { + _searchQuery = searchQuery; + if (searchQuery.value.isNotEmpty) { + store.dispatch(_searchUploadRequestEntriesAction(_uploadRequestEntriesList, searchQuery)); + } else { + store.dispatch(UploadRequestEntrySetSearchResultAction([])); + } + } + + ThunkAction _searchUploadRequestEntriesAction(List entries, SearchQuery searchQuery) { + return (Store store) async { + await _searchUploadRequestEntriesInteractor.execute(entries, searchQuery).then((result) => result.fold((failure) { + if (isInSearchState()) { + store.dispatch(UploadRequestEntrySetSearchResultAction([])); + } + }, (success) { + if (isInSearchState()) { + store.dispatch(UploadRequestEntrySetSearchResultAction(success is SearchUploadRequestEntriesSuccess ? success.uploadRequestEntriesList : [])); + } + })); + }; + } + + bool isInSearchState() { + return store.state.uiState.isInSearchState(); + } + @override void onDisposed() { + _storeStreamSubscription.cancel(); cancelSelection(); clearUploadRequestListAction(); super.onDisposed(); diff --git a/lib/presentation/widget/upload_request_inside/upload_request_inside_widget.dart b/lib/presentation/widget/upload_request_inside/upload_request_inside_widget.dart index 66a180691..cef69973b 100644 --- a/lib/presentation/widget/upload_request_inside/upload_request_inside_widget.dart +++ b/lib/presentation/widget/upload_request_inside/upload_request_inside_widget.dart @@ -51,9 +51,11 @@ import 'package:linshare_flutter_app/presentation/util/helper/responsive_utils.d import 'package:linshare_flutter_app/presentation/util/helper/responsive_widget.dart'; import 'package:linshare_flutter_app/presentation/util/router/app_navigation.dart'; import 'package:linshare_flutter_app/presentation/view/background_widgets/background_widget_builder.dart'; +import 'package:linshare_flutter_app/presentation/view/common/common_view.dart'; import 'package:linshare_flutter_app/presentation/view/context_menu/upload_request_entry_context_menu_action_builder.dart'; import 'package:linshare_flutter_app/presentation/view/multiple_selection_bar/multiple_selection_bar_builder.dart'; import 'package:linshare_flutter_app/presentation/view/multiple_selection_bar/uploadrequest_entry_multiple_selection_action_builder.dart'; +import 'package:linshare_flutter_app/presentation/view/search/search_bottom_bar_builder.dart'; import 'package:linshare_flutter_app/presentation/widget/upload_request_inside/upload_request_document_arguments.dart'; import 'package:linshare_flutter_app/presentation/widget/upload_request_inside/upload_request_document_type.dart'; import 'package:linshare_flutter_app/presentation/widget/upload_request_inside/upload_request_inside_navigator_widget.dart'; @@ -75,6 +77,7 @@ class _UploadRequestInsideWidgetState extends State { final imagePath = getIt(); final _responsiveUtils = getIt(); UploadRequestArguments? _arguments; + final _widgetCommon = getIt(); @override void initState() { @@ -95,6 +98,36 @@ class _UploadRequestInsideWidgetState extends State { @override Widget build(BuildContext context) { + return StoreConnector( + converter: (store) => store.state.uiState.isInSearchState(), + builder: (context, isInSearchState) => + isInSearchState ? _buildSearchViewWidget(context) : _buildDefaultViewWidget()); + } + + Widget _buildSearchViewWidget(BuildContext context) { + return StoreConnector( + converter: (store) => store.state.uploadRequestInsideState, + builder: (_, state) { + if (_viewModel.searchQuery.value.isEmpty) { + return SizedBox.shrink(); + } + if (state.uploadRequestEntries.isEmpty) { + return _widgetCommon.buildNoResultFound(context); + } + return Column(children: [ + _buildMultipleSelectionTopBar(), + _widgetCommon.buildResultCountRow(context, state.uploadRequestEntries.length), + Expanded(child: _buildUploadRequestEntriesListView(state.uploadRequestEntries, state.selectMode)), + (state.selectMode == SelectMode.ACTIVE && state.getAllSelectedEntries().isNotEmpty) + ? _buildMultipleSelectionBottomBar( + context, + state.getAllSelectedEntries()) + : SizedBox.shrink() + ]); + }); + } + + Widget _buildDefaultViewWidget() { return Scaffold( body: Column( children: [ @@ -104,12 +137,24 @@ class _UploadRequestInsideWidgetState extends State { Expanded(child: _buildUploadRequestList()), StoreConnector( converter: (store) => store.state.uploadRequestInsideState, - builder: (context, state) => (state.selectMode == SelectMode.ACTIVE && state.getAllSelectedEntries().isNotEmpty) + builder: (context, state) => (state.selectMode == SelectMode.ACTIVE && + state.getAllSelectedEntries().isNotEmpty) ? _buildMultipleSelectionBottomBar(context, state.getAllSelectedEntries()) - : SizedBox.shrink() - ) + : SizedBox.shrink()) ], ), + bottomNavigationBar: StoreConnector( + converter: (store) => store.state, + builder: (context, appState) { + if (!appState.uiState.isInSearchState() && + appState.uploadRequestInsideState.selectMode != SelectMode.ACTIVE && + appState.uploadRequestInsideState.uploadRequestEntries.isNotEmpty) { + return SearchBottomBarBuilder().key(Key('search_bottom_bar')).onSearchActionClick(() { + _viewModel.openSearchState(); + }).build(); + } + return SizedBox.shrink(); + }), ); } @@ -244,19 +289,18 @@ class _UploadRequestInsideWidgetState extends State { child: _buildEmptyListIndicator()), (success) => RefreshIndicator( onRefresh: () async => _viewModel.requestToGetUploadRequestAndEntries(), - child: _buildLayoutCorrespondingWithState(success, uploadRequestInsideState))) + child: _buildLayoutCorrespondingWithState(uploadRequestInsideState))) ); } - Widget _buildLayoutCorrespondingWithState(state, uploadRequestInsideState) { - if(state is UploadRequestEntryViewState) { - return _buildUploadRequestEntriesListView( - uploadRequestInsideState.uploadRequestEntries, - uploadRequestInsideState.selectMode); - } else if(state is UploadRequestViewState) { - return _buildUploadRequestListView(state.uploadRequests); + Widget _buildLayoutCorrespondingWithState(UploadRequestInsideState uploadRequestInsideState) { + switch (uploadRequestInsideState.uploadRequestDocumentType) { + case UploadRequestDocumentType.recipients: + return _buildUploadRequestListView(uploadRequestInsideState.uploadRequests); + case UploadRequestDocumentType.files: + return _buildUploadRequestEntriesListView( + uploadRequestInsideState.uploadRequestEntries, uploadRequestInsideState.selectMode); } - return SizedBox.shrink(); } Widget _buildEmptyListIndicator() { @@ -274,9 +318,10 @@ class _UploadRequestInsideWidgetState extends State { Widget _buildUploadRequestEntriesListView( List> uploadRequestEntries, SelectMode selectMode) { - if(uploadRequestEntries.isEmpty) { + if (uploadRequestEntries.isEmpty) { return _buildEmptyListIndicator(); } + return ListView.builder( itemCount: uploadRequestEntries.length, itemBuilder: (BuildContext context, int index) { @@ -356,7 +401,7 @@ class _UploadRequestInsideWidgetState extends State { } Widget _buildUploadRequestListView(List uploadRequests) { - if(uploadRequests.isEmpty) { + if (uploadRequests.isEmpty) { return _buildEmptyListIndicator(); } return ListView.builder( @@ -514,5 +559,4 @@ class _UploadRequestInsideWidgetState extends State { .onActionClick((data) => _viewModel.downloadEntries(entries, itemSelectionType: itemSelectionType)) .build(); } - }