diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index ce5415d407..0c497e9302 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -1,4 +1,5 @@ -import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; +import 'package:app_flowy/workspace/application/app/app_listener.dart'; +import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; @@ -10,9 +11,12 @@ import 'package:dartz/dartz.dart'; part 'app_bloc.freezed.dart'; class AppBloc extends Bloc { - final AppRepository repo; + final App app; + final AppService service; final AppListener listener; - AppBloc({required App app, required this.repo, required this.listener}) : super(AppState.initial(app)) { + + AppBloc({required this.app, required this.service, required this.listener}) + : super(AppState.initial(app)) { on((event, emit) async { await event.map(initial: (e) async { listener.startListening( @@ -21,7 +25,8 @@ class AppBloc extends Bloc { ); await _fetchViews(emit); }, createView: (CreateView value) async { - final viewOrFailed = await repo.createView(name: value.name, desc: value.desc, viewType: value.viewType); + final viewOrFailed = + await service.createView(appId: app.id, name: value.name, desc: value.desc, viewType: value.viewType); viewOrFailed.fold( (view) => emit(state.copyWith( latestCreatedView: view, @@ -35,13 +40,13 @@ class AppBloc extends Bloc { }, didReceiveViews: (e) async { await handleDidReceiveViews(e.views, emit); }, delete: (e) async { - final result = await repo.delete(); + final result = await service.delete(appId: app.id); result.fold( (unit) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), ); }, rename: (e) async { - final result = await repo.updateApp(name: e.newName); + final result = await service.updateApp(appId: app.id, name: e.newName); result.fold( (l) => emit(state.copyWith(successOrFailure: left(unit))), (error) => emit(state.copyWith(successOrFailure: right(error))), @@ -81,7 +86,7 @@ class AppBloc extends Bloc { } Future _fetchViews(Emitter emit) async { - final viewsOrFailed = await repo.getViews(); + final viewsOrFailed = await service.getViews(appId: app.id); viewsOrFailed.fold( (apps) => emit(state.copyWith(views: apps)), (error) { diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart similarity index 61% rename from frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart rename to frontend/app_flowy/lib/workspace/application/app/app_listener.dart index 050cf834fb..b2970b931d 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart @@ -1,67 +1,14 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:dartz/dartz.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -import 'helper.dart'; - -class AppRepository { - String appId; - AppRepository({ - required this.appId, - }); - - Future> getAppDesc() { - final request = AppId.create()..value = appId; - - return FolderEventReadApp(request).send(); - } - - Future> createView({ - required String name, - required String desc, - required ViewType viewType, - }) { - final request = CreateViewPayload.create() - ..belongToId = appId - ..name = name - ..desc = desc - ..viewType = viewType; - - return FolderEventCreateView(request).send(); - } - - Future, FlowyError>> getViews() { - final request = AppId.create()..value = appId; - - return FolderEventReadApp(request).send().then((result) { - return result.fold( - (app) => left(app.belongings.items), - (error) => right(error), - ); - }); - } - - Future> delete() { - final request = AppId.create()..value = appId; - return FolderEventDeleteApp(request).send(); - } - - Future> updateApp({String? name}) { - UpdateAppPayload request = UpdateAppPayload.create()..appId = appId; - - if (name != null) { - request.name = name; - } - return FolderEventUpdateApp(request).send(); - } -} typedef AppDidUpdateCallback = void Function(App app); typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); diff --git a/frontend/app_flowy/lib/workspace/application/app/app_service.dart b/frontend/app_flowy/lib/workspace/application/app/app_service.dart new file mode 100644 index 0000000000..e97229fcd7 --- /dev/null +++ b/frontend/app_flowy/lib/workspace/application/app/app_service.dart @@ -0,0 +1,57 @@ +import 'dart:async'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; + +class AppService { + + Future> getAppDesc({required String appId}) { + final request = AppId.create()..value = appId; + + return FolderEventReadApp(request).send(); + } + + Future> createView({ + required String appId, + required String name, + required String desc, + required ViewType viewType, + }) { + final request = CreateViewPayload.create() + ..belongToId = appId + ..name = name + ..desc = desc + ..viewType = viewType; + + return FolderEventCreateView(request).send(); + } + + Future, FlowyError>> getViews({required String appId}) { + final request = AppId.create()..value = appId; + + return FolderEventReadApp(request).send().then((result) { + return result.fold( + (app) => left(app.belongings.items), + (error) => right(error), + ); + }); + } + + Future> delete({required String appId}) { + final request = AppId.create()..value = appId; + return FolderEventDeleteApp(request).send(); + } + + Future> updateApp({required String appId, String? name}) { + UpdateAppPayload request = UpdateAppPayload.create()..appId = appId; + + if (name != null) { + request.name = name; + } + return FolderEventUpdateApp(request).send(); + } +} + + diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 1fa805d34a..f35af8f95e 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,4 +1,6 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart'; +import 'package:app_flowy/workspace/application/app/app_listener.dart'; +import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; @@ -11,7 +13,6 @@ 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/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; @@ -75,7 +76,7 @@ class HomeDepsResolver { getIt.registerFactoryParam( (app, _) => AppBloc( app: app, - repo: AppRepository(appId: app.id), + service: AppService(), listener: AppListener(appId: app.id), ), );