refactor: Put DocShare business logic in a service

This commit is contained in:
MikeWallaceDev 2022-02-28 23:45:17 -05:00
parent afab7f23c4
commit 4180765dc6
3 changed files with 8 additions and 8 deletions

View File

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

View File

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

View File

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