From 360f3df99e8d14b656ad48e6ef4a262c0aa5a71e Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Fri, 21 Jun 2024 15:32:44 +0800 Subject: [PATCH] chore: refacotor share bloc --- .../application/document_share_bloc.dart | 32 +++++++++++++------ .../presentation/share/publish_bloc.dart | 0 .../presentation/share/share_button.dart | 14 ++++---- 3 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_bloc.dart diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart index af0d5081f1..7898888ff6 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart @@ -14,7 +14,7 @@ part 'document_share_bloc.freezed.dart'; class DocumentShareBloc extends Bloc { DocumentShareBloc({ required this.view, - }) : super(const DocumentShareState.initial()) { + }) : super(DocumentShareState.initial()) { on((event, emit) async { await event.when( share: (type, path) async { @@ -23,7 +23,9 @@ class DocumentShareBloc extends Bloc { return; } - emit(const DocumentShareState.loading()); + emit( + state.copyWith(isLoading: true), + ); final exporter = DocumentExporter(view); final FlowyResult result = @@ -46,7 +48,12 @@ class DocumentShareBloc extends Bloc { ); }); - emit(DocumentShareState.finish(result)); + emit( + state.copyWith( + isLoading: false, + exportResult: result, + ), + ); }, ); }); @@ -93,15 +100,20 @@ enum DocumentShareType { @freezed class DocumentShareEvent with _$DocumentShareEvent { - const factory DocumentShareEvent.share(DocumentShareType type, String? path) = - Share; + const factory DocumentShareEvent.share( + DocumentShareType type, + String? path, + ) = Share; } @freezed class DocumentShareState with _$DocumentShareState { - const factory DocumentShareState.initial() = _Initial; - const factory DocumentShareState.loading() = _Loading; - const factory DocumentShareState.finish( - FlowyResult successOrFail, - ) = _Finish; + const factory DocumentShareState({ + required bool isLoading, + FlowyResult? exportResult, + }) = _DocumentShareState; + + factory DocumentShareState.initial() => const DocumentShareState( + isLoading: false, + ); } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_bloc.dart new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart index 5a45fb1750..6ad931c644 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart @@ -33,14 +33,12 @@ class DocumentShareButton extends StatelessWidget { create: (context) => getIt(param1: view), child: BlocListener( listener: (context, state) { - state.mapOrNull( - finish: (state) { - state.successOrFail.fold( - (data) => _handleExportData(context, data), - _handleExportError, - ); - }, - ); + if (state.isLoading == false && state.exportResult != null) { + state.exportResult!.fold( + (data) => _handleExportData(context, data), + _handleExportError, + ); + } }, child: BlocBuilder( builder: (context, state) => SizedBox(