diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index 56ad3378b5..c8f51c6256 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; @@ -11,6 +11,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:dartz/dartz.dart'; import 'dart:async'; + part 'doc_bloc.freezed.dart'; typedef FlutterQuillDocument = Document; @@ -19,7 +20,7 @@ class DocumentBloc extends Bloc { final View view; final DocumentService service; final ViewListener listener; - final TrashRepo trashRepo; + final TrashService trashService; late FlutterQuillDocument document; StreamSubscription? _subscription; @@ -27,7 +28,7 @@ class DocumentBloc extends Bloc { required this.view, required this.service, required this.listener, - required this.trashRepo, + required this.trashService, }) : super(DocumentState.initial()) { on((event, emit) async { await event.map( @@ -41,12 +42,12 @@ class DocumentBloc extends Bloc { emit(state.copyWith(isDeleted: false)); }, deletePermanently: (DeletePermanently value) async { - final result = await trashRepo.deleteViews([Tuple2(view.id, TrashType.TrashView)]); + final result = await trashService.deleteViews([Tuple2(view.id, TrashType.TrashView)]); final newState = result.fold((l) => state.copyWith(forceClose: true), (r) => state); emit(newState); }, restorePage: (RestorePage value) async { - final result = await trashRepo.putback(view.id); + final result = await trashService.putback(view.id); final newState = result.fold((l) => state.copyWith(isDeleted: false), (r) => state); emit(newState); }, diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart index 0829484de0..8bef2e41fd 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -1,20 +1,21 @@ -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; +import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; part 'trash_bloc.freezed.dart'; class TrashBloc extends Bloc { - final TrashRepo repo; + final TrashService service; final TrashListener listener; - TrashBloc({required this.repo, required this.listener}) : super(TrashState.init()) { + TrashBloc({required this.service, required this.listener}) : super(TrashState.init()) { on((event, emit) async { await event.map(initial: (e) async { listener.startListening(trashUpdated: _listenTrashUpdated); - final result = await repo.readTrash(); + final result = await service.readTrash(); emit(result.fold( (object) => state.copyWith(objects: object.items, successOrFailure: left(unit)), (error) => state.copyWith(successOrFailure: right(error)), @@ -22,16 +23,16 @@ class TrashBloc extends Bloc { }, didReceiveTrash: (e) async { emit(state.copyWith(objects: e.trash)); }, putback: (e) async { - final result = await repo.putback(e.trashId); + final result = await service.putback(e.trashId); await _handleResult(result, emit); }, delete: (e) async { - final result = await repo.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); + final result = await service.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); await _handleResult(result, emit); }, deleteAll: (e) async { - final result = await repo.deleteAll(); + final result = await service.deleteAll(); await _handleResult(result, emit); }, restoreAll: (e) async { - final result = await repo.restoreAll(); + final result = await service.restoreAll(); await _handleResult(result, emit); }); }); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart similarity index 64% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart rename to frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart index 3d2d3ee5ad..3d558d1b4e 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart @@ -1,45 +1,13 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -class TrashRepo { - Future> readTrash() { - return FolderEventReadTrash().send(); - } - - Future> putback(String trashId) { - final id = TrashId.create()..id = trashId; - - return FolderEventPutbackTrash(id).send(); - } - - Future> deleteViews(List> trashList) { - final items = trashList.map((trash) { - return TrashId.create() - ..id = trash.value1 - ..ty = trash.value2; - }); - - final ids = RepeatedTrashId(items: items); - return FolderEventDeleteTrash(ids).send(); - } - - Future> restoreAll() { - return FolderEventRestoreAllTrash().send(); - } - - Future> deleteAll() { - return FolderEventDeleteAllTrash().send(); - } -} - typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); class TrashListener { diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart new file mode 100644 index 0000000000..0e7149050a --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart @@ -0,0 +1,37 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; + +class TrashService { + Future> readTrash() { + return FolderEventReadTrash().send(); + } + + Future> putback(String trashId) { + final id = TrashId.create()..id = trashId; + + return FolderEventPutbackTrash(id).send(); + } + + Future> deleteViews(List> trashList) { + final items = trashList.map((trash) { + return TrashId.create() + ..id = trash.value1 + ..ty = trash.value2; + }); + + final ids = RepeatedTrashId(items: items); + return FolderEventDeleteTrash(ids).send(); + } + + Future> restoreAll() { + return FolderEventRestoreAllTrash().send(); + } + + Future> deleteAll() { + return FolderEventDeleteAllTrash().send(); + } +} + diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 15ef0a2733..1fa805d34a 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -6,11 +6,12 @@ import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart'; import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; +import 'package:app_flowy/workspace/application/trash/trash_listener.dart'; +import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; @@ -85,16 +86,16 @@ class HomeDepsResolver { view: view, service: DocumentService(), listener: getIt(param1: view), - trashRepo: getIt(), + trashService: getIt(), ), ); // trash - getIt.registerLazySingleton(() => TrashRepo()); + getIt.registerLazySingleton(() => TrashService()); getIt.registerLazySingleton(() => TrashListener()); getIt.registerFactory( () => TrashBloc( - repo: getIt(), + service: getIt(), listener: getIt(), ), );