config DocBloc

This commit is contained in:
appflowy 2021-07-24 09:57:17 +08:00
parent 3bb12d50bd
commit 1240983730
7 changed files with 91 additions and 23 deletions

View File

@ -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),
);
}

View File

@ -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();
}

View File

@ -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});

View File

@ -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();
}

View File

@ -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)));
//Bloc
getIt.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)));
}
}

View File

@ -29,4 +29,9 @@ class DocRepository {
return EditorEventUpdateDoc(request).send();
}
Future<Either<Unit, EditorError>> closeDoc(
{String? name, String? desc, String? text}) {
throw UnimplementedError();
}
}

View File

@ -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),