Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
config DocBloc
appflowy12409837306d
diff --git a/app_flowy/lib/workspace/application/view/view_bloc.dart b/app_flowy/lib/workspace/application/view/view_bloc.dartindex e69de29bb2..0de85a0d51 100644--- a/app_flowy/lib/workspace/application/view/view_bloc.dart+++ b/app_flowy/lib/workspace/application/view/view_bloc.dart@@ -0,0 +1,44 @@+import 'package:dartz/dartz.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';+import 'package:flutter_bloc/flutter_bloc.dart';+import 'package:freezed_annotation/freezed_annotation.dart';++import 'package:app_flowy/workspace/domain/i_view.dart';++part 'view_bloc.freezed.dart';++class ViewBloc extends Bloc<ViewEvent, ViewState> {+ final IView iViewImpl;++ ViewBloc({+ required this.iViewImpl,+ }) : super(ViewState.initial());++ @override+ Stream<ViewState> mapEventToState(ViewEvent event) async* {+ yield* event.map(initial: (_) async* {+ yield state;+ });+ }+}++@freezed+abstract class ViewEvent with _$ViewEvent {+ const factory ViewEvent.initial() = Initial;+}++@freezed+abstract class ViewState implements _$ViewState {+ const factory ViewState({+ required bool isLoading,+ required Option<View> view,+ required Either<Unit, WorkspaceError> successOrFailure,+ }) = _ViewState;++ factory ViewState.initial() => ViewState(+ isLoading: false,+ view: none(),+ successOrFailure: left(unit),+ );+}diff --git a/app_flowy/lib/workspace/domain/i_doc.dart b/app_flowy/lib/workspace/domain/i_doc.dartindex 957aeb1f04..ea38f54c18 100644--- a/app_flowy/lib/workspace/domain/i_doc.dart+++ b/app_flowy/lib/workspace/domain/i_doc.dart@@ -3,8 +3,8 @@ import 'package:dartz/dartz.dart';import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart';abstract class IDoc {- Future<Either<DocDescription, EditorError>> createDoc();Future<Either<Doc, EditorError>> readDoc();- Future<Either<Unit, EditorError>> updateDoc();+ Future<Either<Unit, EditorError>> updateDoc(+ {String? name, String? desc, String? text});Future<Either<Unit, EditorError>> closeDoc();}diff --git a/app_flowy/lib/workspace/domain/i_view.dart b/app_flowy/lib/workspace/domain/i_view.dartindex 4feabb77f4..2334b65e57 100644--- a/app_flowy/lib/workspace/domain/i_view.dart+++ b/app_flowy/lib/workspace/domain/i_view.dart@@ -1,7 +1,13 @@+import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';+import 'package:dartz/dartz.dart';typedef ViewUpdatedCallback = void Function(View view);+abstract class IView {+ Future<Either<View, WorkspaceError>> readView();+}+abstract class IViewWatch {void startWatching({ViewUpdatedCallback? updatedCallback});diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack.dartindex 4c861171db..1dc5c580dc 100644--- a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart+++ b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart@@ -63,7 +63,7 @@ List<Widget> _buildStackWidget(HomeStackView stackView) {case ViewType.Blank:return BlankPage(stackView: stackView as BlankStackView);case ViewType.Doc:- return DocPage(stackView: stackView as DocPageContext);+ return DocPage(stackView: stackView as DocPageStackView);default:return BlankPage(stackView: stackView as BlankStackView);}@@ -78,7 +78,7 @@ HomeStackView stackViewFromView(View view) {case ViewType.Blank:return const BlankStackView();case ViewType.Doc:- return DocPageContext(view);+ return DocPageStackView(view);default:return const BlankStackView();}diff --git a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/app_flowy/lib/workspace/infrastructure/deps_resolver.dartindex 02b235ff65..417e526c4d 100644--- a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart+++ b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart@@ -2,39 +2,47 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart';import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart';import 'package:app_flowy/workspace/application/menu/menu_bloc.dart';import 'package:app_flowy/workspace/application/menu/menu_watch.dart';+import 'package:app_flowy/workspace/application/view/view_bloc.dart';+import 'package:app_flowy/workspace/domain/i_doc.dart';+import 'package:app_flowy/workspace/domain/i_view.dart';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_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/view_repo.dart';import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart';import 'package:get_it/get_it.dart';+import 'i_view_impl.dart';+class HomeDepsResolver {static Future<void> resolve(GetIt getIt) async {//getIt.registerLazySingleton<HomePageStack>(() => HomePageStack());//App- getIt.registerFactoryParam<AppRepository, String, void>(- (appId, _) => AppRepository(appId: appId));- getIt.registerFactoryParam<AppWatchRepository, String, void>(- (appId, _) => AppWatchRepository(appId: appId));getIt.registerFactoryParam<IApp, String, void>(- (appId, _) => IAppImpl(repo: getIt<AppRepository>(param1: appId)));- getIt.registerFactoryParam<IAppWatch, String, void>((appId, _) =>- IAppWatchImpl(repo: getIt<AppWatchRepository>(param1: appId)));+ (appId, _) => IAppImpl(repo: AppRepository(appId: appId)));+ getIt.registerFactoryParam<IAppWatch, String, void>(+ (appId, _) => IAppWatchImpl(repo: AppWatchRepository(appId: appId)));//workspace- getIt.registerFactoryParam<WorkspaceRepo, String, void>(- (workspaceId, _) => WorkspaceRepo(workspaceId: workspaceId));- getIt.registerFactoryParam<WorkspaceWatchRepo, String, void>(- (workspaceId, _) => WorkspaceWatchRepo(workspaceId: workspaceId));-- getIt.registerFactoryParam<IWorkspace, String, void>((workspacId, _) =>- IWorkspaceImpl(repo: getIt<WorkspaceRepo>(param1: workspacId)));+ getIt.registerFactoryParam<IWorkspace, String, void>((workspaceId, _) =>+ IWorkspaceImpl(repo: WorkspaceRepo(workspaceId: workspaceId)));getIt.registerFactoryParam<IWorkspaceWatch, String, void>((workspacId, _) =>- IWorkspaceWatchImpl(- repo: getIt<WorkspaceWatchRepo>(param1: workspacId)));+ IWorkspaceWatchImpl(repo: WorkspaceWatchRepo(workspaceId: workspacId)));++ // View+ getIt.registerFactoryParam<IView, String, void>(+ (viewId, _) => IViewImpl(repo: ViewRepository(viewId: viewId)));+ getIt.registerFactoryParam<IViewWatch, String, void>((viewId, _) =>+ IViewWatchImpl(repo: ViewWatchRepository(viewId: viewId)));++ // Doc+ getIt.registerFactoryParam<IDoc, String, void>(+ (docId, _) => IDocImpl(repo: DocRepository(docId: docId)));//BlocgetIt.registerFactoryParam<MenuBloc, String, void>(@@ -46,6 +54,11 @@ class HomeDepsResolver {(appId, _) => AppBloc(getIt<IApp>(param1: appId)));getIt.registerFactoryParam<AppWatchBloc, String, void>((appId, _) => AppWatchBloc(getIt<IAppWatch>(param1: appId)));- // AppWatchBloc++ getIt.registerFactoryParam<ViewBloc, String, void>(+ (viewId, _) => ViewBloc(iViewImpl: getIt<IView>(param1: viewId)));++ // getIt.registerFactoryParam<ViewBloc, String, void>(+ // (viewId, _) => ViewBloc(iViewImpl: getIt<IView>(param1: viewId)));}}diff --git a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dartindex ed4aac381f..3acf3ae0bd 100644--- a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart+++ b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart@@ -29,4 +29,9 @@ class DocRepository {return EditorEventUpdateDoc(request).send();}++ Future<Either<Unit, EditorError>> closeDoc(+ {String? name, String? desc, String? text}) {+ throw UnimplementedError();+ }}diff --git a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dartindex d1b1a95ce8..3a3bf78140 100644--- a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart+++ b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart@@ -18,7 +18,7 @@ class ViewRepository {required this.viewId,});- Future<Either<View, WorkspaceError>> getView() {+ Future<Either<View, WorkspaceError>> readView() {final request = QueryViewRequest.create()..viewId = viewId;return WorkspaceEventReadView(request).send();}@@ -57,7 +57,7 @@ class ViewWatchRepository {if (_updatedCallback == null) {return;}- _repo.getView().then((result) {+ _repo.readView().then((result) {result.fold((view) => _updatedCallback!(view),(error) => Log.error(error),