Skip to content

Commit

Permalink
copy upload request entries to my space presentation layer (linagora#573
Browse files Browse the repository at this point in the history
)

(cherry picked from commit d321719)
  • Loading branch information
Julian KOUNE authored and hoangdat committed Sep 28, 2021
1 parent 61807ac commit 2fe5da8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/presentation/di/module/widget_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ class WidgetModule {
getIt.get<GetAllUploadRequestEntriesInteractor>(),
getIt<DownloadUploadRequestEntriesInteractor>(),
getIt<DownloadMultipleUploadRequestEntryIOSInteractor>(),
getIt<SearchUploadRequestEntriesInteractor>()
getIt<SearchUploadRequestEntriesInteractor>(),
getIt<CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor>()
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ final uploadRequestInsideReducer = combineReducers<UploadRequestInsideState>([
state.unSelectAllUploadRequestEntry()),
TypedReducer<UploadRequestInsideState, UploadRequestEntrySetSearchResultAction>((UploadRequestInsideState state, UploadRequestEntrySetSearchResultAction action) =>
state.setSearchResult(newSearchResult: action.uploadRequestEntries)),
TypedReducer<UploadRequestInsideState, CleanUploadRequestInsideAction>((UploadRequestInsideState state, _) => state.clearViewState()),
TypedReducer<UploadRequestInsideState, CleanUploadRequestInsideAction>((UploadRequestInsideState state, _) =>
state.clearViewState()),
]);
39 changes: 35 additions & 4 deletions lib/presentation/util/toast_message_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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/add_recipients_upload_request_group_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/delete_shared_space_members_state.dart';
Expand All @@ -64,6 +65,7 @@ import 'package:linshare_flutter_app/presentation/redux/states/shared_space_node
import 'package:linshare_flutter_app/presentation/redux/states/shared_space_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/upload_file_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/upload_request_group_state.dart';
import 'package:linshare_flutter_app/presentation/redux/states/upload_request_inside_state.dart';
import 'package:linshare_flutter_app/presentation/util/app_toast.dart';
import 'package:redux/redux.dart';

Expand All @@ -85,6 +87,7 @@ class ToastMessageHandler {
_handleSharedSpaceNodeVersionsToastMessage(context, event.sharedSpaceNodeVersionsState);
_handleAddRecipientUploadRequestGroupToastMessage(context, event.addRecipientsUploadRequestGroupState);
_handleUploadRequestGroupToastMessage(context, event.uploadRequestGroupState);
_handleUploadRequestInsideToastMessage(context, event.uploadRequestInsideState);
});
}

Expand Down Expand Up @@ -365,10 +368,6 @@ class ToastMessageHandler {
});
}

void _cleanAddRecipientUploadRequestGroupViewState() {
_store.dispatch(CleanAddRecipientsUploadRequestGroupAction());
}

void _handleUploadRequestGroupToastMessage(BuildContext context, UploadRequestGroupState requestGroupState) {
requestGroupState.viewState.fold((failure) {
if (failure is UpdateUploadRequestGroupStateFailure) {
Expand All @@ -392,6 +391,38 @@ class ToastMessageHandler {
});
}

void _handleUploadRequestInsideToastMessage(BuildContext context, UploadRequestInsideState uploadRequestInsideState) {
uploadRequestInsideState.viewState.fold((failure) {
if (failure is CopyToMySpaceFailure) {
appToast.showErrorToast(AppLocalizations.of(context).the_file_could_not_be_copied);
_cleanUploadRequestInsideViewState();
} else if (failure is CopyMultipleToMySpaceFromUploadRequestEntriesAllFailure) {
appToast.showErrorToast(AppLocalizations.of(context).cannot_copy_files_to_my_space);
_cleanUploadRequestInsideViewState();
}
}, (success) {
if (success is CopyToMySpaceViewState) {
appToast.showToast(AppLocalizations.of(context).the_file_has_been_copied_successfully);
_cleanUploadRequestInsideViewState();
} else if (success is CopyMultipleToMySpaceFromUploadRequestEntriesAllSuccessViewState) {
appToast.showToast(AppLocalizations.of(context).all_items_have_been_copied_to_my_space);
_cleanUploadRequestInsideViewState();
} else if (success is CopyMultipleToMySpaceFromUploadRequestEntriesHasSomeFilesViewState) {
appToast.showToast(AppLocalizations.of(context).some_items_have_been_copied_to_my_space);
_cleanUploadRequestInsideViewState();
}
});
}

void _cleanAddRecipientUploadRequestGroupViewState() {
_store.dispatch(CleanAddRecipientsUploadRequestGroupAction());
}

void _cleanUploadRequestInsideViewState() {
_store.dispatch(CleanUploadRequestInsideAction());
}


void _cleanMySpaceViewState() {
_store.dispatch(CleanMySpaceStateAction());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ class UploadRequestInsideViewModel extends BaseViewModel {
SearchQuery get searchQuery => _searchQuery;
List<UploadRequestEntry> _uploadRequestEntriesList = [];

final CopyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor;

UploadRequestInsideViewModel(
Store<AppState> store,
this._appNavigation,
this._getAllUploadRequestsInteractor,
this._getAllUploadRequestEntriesInteractor,
this._downloadEntriesInteractor,
this._downloadMultipleEntryIOSInteractor,
this._searchUploadRequestEntriesInteractor
this._searchUploadRequestEntriesInteractor,
this._copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor
) : super(store) {
_storeStreamSubscription = store.onChange.listen((event) {
event.uploadRequestInsideState.viewState.fold((failure) => null, (success) {
Expand Down Expand Up @@ -381,8 +384,25 @@ class UploadRequestInsideViewModel extends BaseViewModel {
};
}

bool isInSearchState() {
return store.state.uiState.isInSearchState();
bool isInSearchState()
=> store.state.uiState.isInSearchState();

void copyToMySpace(List<UploadRequestEntry> entries, {ItemSelectionType itemSelectionType = ItemSelectionType.single}) {
_appNavigation.popBack();
if (itemSelectionType == ItemSelectionType.multiple) {
cancelSelection();
}

store.dispatch(_copyToMySpaceAction(entries));
}

OnlineThunkAction _copyToMySpaceAction(List<UploadRequestEntry> entries) {
return OnlineThunkAction((Store<AppState> store) async {
await _copyMultipleFilesFromUploadRequestEntriesToMySpaceInteractor.execute(entries)
.then((result) => result.fold(
(failure) => store.dispatch(UploadRequestInsideAction(Left(failure))),
(success) => store.dispatch(UploadRequestInsideAction(Right(success)))));
});
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,15 @@ class _UploadRequestInsideWidgetState extends State<UploadRequestInsideWidget> {
List<Widget> _moreActionList(BuildContext context, List<UploadRequestEntry> entries) {
return [
_exportFileAction(entries, itemSelectionType: ItemSelectionType.multiple),
_copyToMySpaceAction(entries, itemSelectionType: ItemSelectionType.multiple),
if (Platform.isAndroid) _downloadFilesAction(entries, itemSelectionType: ItemSelectionType.multiple),
];
}

List<Widget> _contextMenuActiveCloseActionTiles(BuildContext context, UploadRequestEntry entry) {
return [
_exportFileAction([entry]),
_copyToMySpaceAction([entry]),
if (Platform.isAndroid) _downloadFilesAction([entry])
];
}
Expand All @@ -559,4 +561,15 @@ class _UploadRequestInsideWidgetState extends State<UploadRequestInsideWidget> {
.onActionClick((data) => _viewModel.downloadEntries(entries, itemSelectionType: itemSelectionType))
.build();
}

Widget _copyToMySpaceAction(List<UploadRequestEntry> entries,
{ItemSelectionType itemSelectionType = ItemSelectionType.single}) {
return UploadRequestEntryContextMenuTileBuilder(
Key('copy_to_my_space_context_menu_action'),
SvgPicture.asset(imagePath.icCopy, width: 24, height: 24, fit: BoxFit.fill),
AppLocalizations.of(context).copy_to_my_space,
entries.first)
.onActionClick((data) => _viewModel.copyToMySpace(entries, itemSelectionType: itemSelectionType))
.build();
}
}

0 comments on commit 2fe5da8

Please sign in to comment.