Skip to content

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.

refactor: Put DocShare business logic in a service

MikeWallaceDev4180765dc603
diff --git a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart
index 460a9986c7..0eb9ec43a5 100644
--- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart
+++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart
@@ -1,5 +1,5 @@
+import 'package:app_flowy/workspace/application/doc/share_service.dart';
import 'package:app_flowy/workspace/infrastructure/markdown/delta_markdown.dart';
-import 'package:app_flowy/workspace/infrastructure/repos/share_repo.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/share.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
@@ -9,13 +9,13 @@ import 'package:dartz/dartz.dart';
part 'share_bloc.freezed.dart';
class DocShareBloc extends Bloc<DocShareEvent, DocShareState> {
- ShareRepo repo;
+ ShareService service;
View view;
- DocShareBloc({required this.view, required this.repo}) : super(const DocShareState.initial()) {
+ DocShareBloc({required this.view, required this.service}) : super(const DocShareState.initial()) {
on<DocShareEvent>((event, emit) async {
await event.map(
shareMarkdown: (ShareMarkdown value) async {
- await repo.exportMarkdown(view.id).then((result) {
+ await service.exportMarkdown(view.id).then((result) {
result.fold(
(value) => emit(DocShareState.finish(left(_convertDeltaToMarkdown(value)))),
(error) => emit(DocShareState.finish(right(error))),
diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart b/frontend/app_flowy/lib/workspace/application/doc/share_service.dart
similarity index 97%
rename from frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart
rename to frontend/app_flowy/lib/workspace/application/doc/share_service.dart
index ffd95d1e0b..a7d47cb064 100644
--- a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart
+++ b/frontend/app_flowy/lib/workspace/application/doc/share_service.dart
@@ -4,7 +4,7 @@ import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
-class ShareRepo {
+class ShareService {
Future<Either<ExportData, FlowyError>> export(String docId, ExportType type) {
final request = ExportPayload.create()
..docId = docId
diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart
index 125a93f2cf..bf1e892700 100644
--- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart
+++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart
@@ -6,6 +6,7 @@ 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';
+import 'package:app_flowy/workspace/application/doc/share_service.dart';
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';
@@ -23,7 +24,6 @@ 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-user-data-model/user_profile.pb.dart';
import 'package:get_it/get_it.dart';
-import 'repos/share_repo.dart';
class HomeDepsResolver {
static Future<void> resolve(GetIt getIt) async {
@@ -108,8 +108,8 @@ class HomeDepsResolver {
);
// share
- getIt.registerLazySingleton<ShareRepo>(() => ShareRepo());
+ getIt.registerLazySingleton<ShareService>(() => ShareService());
getIt.registerFactoryParam<DocShareBloc, View, void>(
- (view, _) => DocShareBloc(view: view, repo: getIt<ShareRepo>()));
+ (view, _) => DocShareBloc(view: view, service: getIt<ShareService>()));
}
}