Skip to content

Commit

Permalink
search upload request inside presentation layer (linagora#523)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0b13444)
  • Loading branch information
Julian KOUNE authored and hoangdat committed Sep 28, 2021
1 parent 99925d5 commit 9ba62bb
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 37 deletions.
6 changes: 6 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
6 changes: 6 additions & 0 deletions lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
8 changes: 7 additions & 1 deletion lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {}
}
}
6 changes: 6 additions & 0 deletions lib/l10n/intl_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
6 changes: 6 additions & 0 deletions lib/l10n/intl_vi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
1 change: 1 addition & 0 deletions lib/presentation/di/module/widget_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ class WidgetModule {
getIt.get<GetAllUploadRequestEntriesInteractor>(),
getIt<DownloadUploadRequestEntriesInteractor>(),
getIt<DownloadMultipleUploadRequestEntryIOSInteractor>(),
getIt<SearchUploadRequestEntriesInteractor>()
));
}

Expand Down
6 changes: 6 additions & 0 deletions lib/presentation/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppLocalizations> {
Expand Down
12 changes: 12 additions & 0 deletions lib/presentation/redux/actions/upload_request_inside_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ class UploadRequestSelectAllEntryAction extends ActionOffline {
class UploadRequestUnSelectAllEntryAction extends ActionOffline {
UploadRequestUnSelectAllEntryAction();
}

@immutable
class UploadRequestEntrySetSearchResultAction extends ActionOffline {
final List<UploadRequestEntry> uploadRequestEntries;

UploadRequestEntrySetSearchResultAction(this.uploadRequestEntries);
}

@immutable
class CleanUploadRequestInsideAction extends ActionOffline {
CleanUploadRequestInsideAction();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import 'package:redux/redux.dart';

final uploadRequestInsideReducer = combineReducers<UploadRequestInsideState>([
TypedReducer<UploadRequestInsideState, StartUploadRequestInsideLoadingAction>((UploadRequestInsideState state, _) => state.startLoadingState()),
TypedReducer<UploadRequestInsideState, UploadRequestInsideAction>((UploadRequestInsideState state, UploadRequestInsideAction action) => state.sendViewState(viewState: action.viewState)),
TypedReducer<UploadRequestInsideState, SetUploadRequestsArgumentsAction>((UploadRequestInsideState state, SetUploadRequestsArgumentsAction action) =>
state.setUploadRequestArgument(newUploadRequestArguments: action.arguments)),
TypedReducer<UploadRequestInsideState, GetAllUploadRequestsAction>((UploadRequestInsideState state, GetAllUploadRequestsAction action) =>
Expand Down Expand Up @@ -67,4 +68,7 @@ final uploadRequestInsideReducer = combineReducers<UploadRequestInsideState>([
state.selectAllUploadRequestEntry()),
TypedReducer<UploadRequestInsideState, UploadRequestUnSelectAllEntryAction>((UploadRequestInsideState state, UploadRequestUnSelectAllEntryAction action) =>
state.unSelectAllUploadRequestEntry()),
TypedReducer<UploadRequestInsideState, UploadRequestEntrySetSearchResultAction>((UploadRequestInsideState state, UploadRequestEntrySetSearchResultAction action) =>
state.setSearchResult(newSearchResult: action.uploadRequestEntries)),
TypedReducer<UploadRequestInsideState, CleanUploadRequestInsideAction>((UploadRequestInsideState state, _) => state.clearViewState()),
]);
5 changes: 3 additions & 2 deletions lib/presentation/redux/states/ui_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -112,5 +112,6 @@ enum SearchDestination {
sharedSpace,
allSharedSpaces,
receivedShares,
uploadRequestGroups
uploadRequestGroups,
uploadRequestInside
}
48 changes: 40 additions & 8 deletions lib/presentation/redux/states/upload_request_inside_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Failure, Success> viewState}) {
return UploadRequestInsideState(
viewState, uploadRequests, uploadRequestEntries, selectMode, uploadRequestDocumentType, null, null);
viewState,
uploadRequests,
uploadRequestEntries,
selectMode,
uploadRequestDocumentType,
uploadRequestGroup,
selectedUploadRequest
);
}

UploadRequestInsideState setUploadRequestArgument({required UploadRequestArguments newUploadRequestArguments}) {
Expand Down Expand Up @@ -132,12 +146,12 @@ class UploadRequestInsideState extends LinShareState with EquatableMixin {
UploadRequestInsideState selectUploadRequestEntry(SelectableElement<UploadRequestEntry> selectedUploadRequestEntry) {
uploadRequestEntries.firstWhere((entry) => entry == selectedUploadRequestEntry).toggleSelect();
return UploadRequestInsideState(
viewState,
uploadRequests,
uploadRequestEntries,
viewState,
uploadRequests,
uploadRequestEntries,
SelectMode.ACTIVE,
uploadRequestDocumentType,
uploadRequestGroup,
uploadRequestDocumentType,
uploadRequestGroup,
selectedUploadRequest);
}

Expand Down Expand Up @@ -183,6 +197,24 @@ class UploadRequestInsideState extends LinShareState with EquatableMixin {
);
}

UploadRequestInsideState setSearchResult({required List<UploadRequestEntry> 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<UploadRequestEntry>(entry, SelectMode.ACTIVE)
: SelectableElement<UploadRequestEntry>(entry, SelectMode.INACTIVE)).toList(),
selectMode,
uploadRequestDocumentType,
uploadRequestGroup,
selectedUploadRequest
);
}

@override
List<Object?> get props =>
[...super.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
});
}

Expand Down Expand Up @@ -102,6 +104,16 @@ class HomeAppBarViewModel extends BaseViewModel {
});
}

void _handleUploadRequestInsideViewState(
TextEditingController _typeAheadController, Either<Failure, Success> viewState) {
viewState.fold((failure) => null, (success) {
if (success is DisableSearchViewState) {
_typeAheadController.clear();
store.dispatch(CleanUploadRequestInsideAction());
}
});
}

@override
void onDisposed() {
_streamSubscription.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ class _HomeAppBarWidgetState extends State<HomeAppBarWidget> {
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 '';
}
Expand Down
13 changes: 10 additions & 3 deletions lib/presentation/widget/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class CreatedUploadRequestGroupViewModel extends UploadRequestGroupTabViewModel
SearchQuery get searchQuery => _searchQuery;

CreatedUploadRequestGroupViewModel(
Store<AppState> store,
this._appNavigation,
this._getAllUploadRequestGroupsInteractor,
Store<AppState> store,
this._appNavigation,
this._getAllUploadRequestGroupsInteractor,
this._getSorterInteractor,
this._saveSorterInteractor,
this._sortInteractor,
this._saveSorterInteractor,
this._sortInteractor,
this._searchUploadRequestGroupsInteractor,
this._multipleUploadRequestGroupStateInteractor) : super(
store,
Expand Down
Loading

0 comments on commit 9ba62bb

Please sign in to comment.