diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart index 79d94a020b..fb1e9dc7c9 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:app_flowy/workspace/domain/i_workspace.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; import 'package:app_flowy/workspace/presentation/stack_page/blank/blank_page.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_log/flowy_log.dart'; @@ -12,9 +12,9 @@ import 'package:flutter_bloc/flutter_bloc.dart'; part 'menu_bloc.freezed.dart'; class MenuBloc extends Bloc { - final IWorkspace workspaceManager; - final IWorkspaceListener listener; - MenuBloc({required this.workspaceManager, required this.listener}) : super(MenuState.initial()) { + final WorkspaceRepo repo; + final WorkspaceListener listener; + MenuBloc({required this.repo, required this.listener}) : super(MenuState.initial()) { on((event, emit) async { await event.map( initial: (e) async { @@ -48,7 +48,7 @@ class MenuBloc extends Bloc { } Future _performActionOnCreateApp(CreateApp event, Emitter emit) async { - final result = await workspaceManager.createApp(name: event.name, desc: event.desc); + final result = await repo.createApp(event.name, event.desc ?? ""); result.fold( (app) => {}, (error) { @@ -60,7 +60,7 @@ class MenuBloc extends Bloc { // ignore: unused_element Future _fetchApps(Emitter emit) async { - final appsOrFail = await workspaceManager.getApps(); + final appsOrFail = await repo.getApps(); emit(appsOrFail.fold( (apps) => state.copyWith(apps: some(apps)), (error) { diff --git a/frontend/app_flowy/lib/workspace/domain/i_workspace.dart b/frontend/app_flowy/lib/workspace/domain/i_workspace.dart deleted file mode 100644 index 6e0393a1cf..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_workspace.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -typedef WorkspaceAppsChangedCallback = void Function(Either, FlowyError> appsOrFail); - -typedef WorkspaceUpdatedCallback = void Function(String name, String desc); - -abstract class IWorkspace { - Future> createApp({required String name, String? desc}); - - Future, FlowyError>> getApps(); -} - -abstract class IWorkspaceListener { - void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}); - - Future stop(); -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 626a2483f5..5b481f9421 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -14,7 +14,6 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/i_app_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart'; -import 'package:app_flowy/workspace/infrastructure/i_workspace_impl.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; @@ -46,10 +45,8 @@ class HomeDepsResolver { (appId, _) => IAppListenerhImpl(repo: AppListenerRepository(appId: appId))); //workspace - getIt.registerFactoryParam( - (user, workspaceId) => IWorkspaceImpl(repo: WorkspaceRepo(user: user, workspaceId: workspaceId))); - getIt.registerFactoryParam((user, workspaceId) => - IWorkspaceListenerImpl(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId))); + getIt.registerFactoryParam( + (user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId))); // View getIt.registerFactoryParam((view, _) => IViewImpl(repo: ViewRepository(view: view))); @@ -72,8 +69,8 @@ class HomeDepsResolver { //Menu Bloc getIt.registerFactoryParam( (user, workspaceId) => MenuBloc( - workspaceManager: getIt(param1: user, param2: workspaceId), - listener: getIt(param1: user, param2: workspaceId), + repo: WorkspaceRepo(user: user, workspaceId: workspaceId), + listener: getIt(param1: user, param2: workspaceId), ), ); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart deleted file mode 100644 index ef1d35fe96..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:app_flowy/workspace/domain/i_workspace.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -export 'package:app_flowy/workspace/domain/i_workspace.dart'; - -class IWorkspaceImpl extends IWorkspace { - WorkspaceRepo repo; - IWorkspaceImpl({ - required this.repo, - }); - - @override - Future> createApp({required String name, String? desc}) { - return repo.createApp(name, desc ?? ""); - } - - @override - Future, FlowyError>> getApps() { - return repo.getApps().then((result) { - return result.fold( - (apps) => left(apps), - (error) => right(error), - ); - }); - } -} - -class IWorkspaceListenerImpl extends IWorkspaceListener { - WorkspaceListenerRepo repo; - IWorkspaceListenerImpl({ - required this.repo, - }); - - @override - void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { - repo.startListening(appsChanged: addAppCallback, update: updatedCallback); - } - - @override - Future stop() async { - await repo.close(); - } -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart index 8e981fc085..8bba568fc3 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart @@ -12,9 +12,7 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.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 'package:app_flowy/generated/locale_keys.g.dart'; -import 'package:app_flowy/workspace/domain/i_workspace.dart'; import 'helper.dart'; @@ -26,9 +24,9 @@ class WorkspaceRepo { required this.workspaceId, }); - Future> createApp(String appName, String desc) { + Future> createApp(String name, String desc) { final request = CreateAppRequest.create() - ..name = appName + ..name = name ..workspaceId = workspaceId ..desc = desc; return FolderEventCreateApp(request).send(); @@ -127,3 +125,22 @@ class WorkspaceListenerRepo { // _update = null; } } + +typedef WorkspaceAppsChangedCallback = void Function(Either, FlowyError> appsOrFail); + +typedef WorkspaceUpdatedCallback = void Function(String name, String desc); + +class WorkspaceListener { + WorkspaceListenerRepo repo; + WorkspaceListener({ + required this.repo, + }); + + void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { + repo.startListening(appsChanged: addAppCallback, update: updatedCallback); + } + + Future stop() async { + await repo.close(); + } +}