diff --git a/app/lib/controller/collections_controller.dart b/app/lib/controller/collections_controller.dart index 95f9647b..975c064a 100644 --- a/app/lib/controller/collections_controller.dart +++ b/app/lib/controller/collections_controller.dart @@ -19,6 +19,7 @@ import 'package:nc_photos/or_null.dart'; import 'package:nc_photos/rx_extension.dart'; import 'package:nc_photos/use_case/collection/create_collection.dart'; import 'package:nc_photos/use_case/collection/edit_collection.dart'; +import 'package:nc_photos/use_case/collection/import_pending_shared_collection.dart'; import 'package:nc_photos/use_case/collection/list_collection.dart'; import 'package:nc_photos/use_case/collection/remove_collections.dart'; import 'package:nc_photos/use_case/collection/share_collection.dart'; @@ -261,6 +262,25 @@ class CollectionsController { } } + /// See [ImportPendingSharedCollection] + Future importPendingSharedCollection( + Collection collection) async { + try { + final newCollection = + await ImportPendingSharedCollection(_c)(account, collection); + _dataStreamController.addWithValue((v) => v.copyWith( + data: _prepareDataFor([ + newCollection, + ...v.data.map((e) => e.collection), + ]), + )); + return newCollection; + } catch (e, stackTrace) { + _dataStreamController.addError(e, stackTrace); + return null; + } + } + Future _load() async { var lastData = const CollectionStreamEvent( data: [], diff --git a/app/lib/widget/collection_browser/bloc.dart b/app/lib/widget/collection_browser/bloc.dart index 534a9420..b6cfd1c8 100644 --- a/app/lib/widget/collection_browser/bloc.dart +++ b/app/lib/widget/collection_browser/bloc.dart @@ -140,10 +140,11 @@ class _Bloc extends Bloc<_Event, _State> implements BlocTag { Future _onImportPendingSharedCollection( _ImportPendingSharedCollection ev, Emitter<_State> emit) async { _log.info(ev); - // pending collections are always ad hoc - final newCollection = - await ImportPendingSharedCollection(_c)(account, state.collection); - emit(state.copyWith(importResult: newCollection)); + final newCollection = await collectionsController + .importPendingSharedCollection(state.collection); + if (newCollection != null) { + emit(state.copyWith(importResult: newCollection)); + } } void _onBeginEdit(_BeginEdit ev, Emitter<_State> emit) {