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 85fd02ec5a..c57a43c703 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 @@ -13,6 +13,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'document_share_bloc.freezed.dart'; +// todo: replace with beta const _url = 'https://test.appflowy.com'; class DocumentShareBloc extends Bloc { @@ -80,6 +81,7 @@ class DocumentShareBloc extends Bloc { state.copyWith( isPublished: true, publishResult: FlowySuccess(null), + unpublishResult: null, url: '$_url/${result.namespace}/$publishName', ), ); @@ -92,12 +94,20 @@ class DocumentShareBloc extends Bloc { publishResult: FlowyResult.failure( FlowyError(msg: 'publish error: $e'), ), + unpublishResult: null, url: '', ), ); } }, unPublish: () async { + emit( + state.copyWith( + publishResult: null, + unpublishResult: null, + ), + ); + final result = await ViewBackendService.unpublish(view); final isPublished = !result.isSuccess; result.onFailure((f) { @@ -108,7 +118,8 @@ class DocumentShareBloc extends Bloc { state.copyWith( isPublished: isPublished, publishResult: null, - url: '', + unpublishResult: result, + url: result.fold((_) => '', (_) => state.url), ), ); }, @@ -213,6 +224,7 @@ class DocumentShareState with _$DocumentShareState { FlowyResult? exportResult, required bool isPublished, FlowyResult? publishResult, + FlowyResult? unpublishResult, required String url, required String viewName, }) = _DocumentShareState; diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_tab.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_tab.dart index b0145c64d6..04029fcfc4 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_tab.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/publish_tab.dart @@ -22,19 +22,7 @@ class PublishTab extends StatelessWidget { Widget build(BuildContext context) { return BlocConsumer( listener: (context, state) { - if (state.publishResult != null) { - state.publishResult!.fold( - (value) => showToastNotification( - context, - message: LocaleKeys.publish_publishSuccessfully.tr(), - ), - (error) => showToastNotification( - context, - message: - '${LocaleKeys.publish_publishFailed.tr()}: ${error.code}', - ), - ); - } + _showToast(context, state); }, builder: (context, state) { return state.isPublished @@ -64,6 +52,33 @@ class PublishTab extends StatelessWidget { }, ); } + + void _showToast(BuildContext context, DocumentShareState state) { + if (state.publishResult != null) { + state.publishResult!.fold( + (value) => showToastNotification( + context, + message: LocaleKeys.publish_publishSuccessfully.tr(), + ), + (error) => showToastNotification( + context, + message: '${LocaleKeys.publish_publishFailed.tr()}: ${error.code}', + ), + ); + } else if (state.unpublishResult != null) { + state.unpublishResult!.fold( + (value) => showToastNotification( + context, + message: LocaleKeys.publish_unpublishSuccessfully.tr(), + ), + (error) => showToastNotification( + context, + message: LocaleKeys.publish_unpublishFailed.tr(), + description: error.msg, + ), + ); + } + } } class _PublishedWidget extends StatefulWidget { diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart index 04ef09ba5f..63df9f8d63 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart @@ -295,7 +295,14 @@ void showToastNotification( type: ToastificationType.success, style: ToastificationStyle.flat, title: FlowyText(message), - description: description != null ? FlowyText(description) : null, + description: description != null + ? FlowyText.regular( + description, + fontSize: 12, + lineHeight: 1.2, + maxLines: 3, + ) + : null, alignment: Alignment.bottomCenter, autoCloseDuration: const Duration(seconds: 4), showProgressBar: false, diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json index 78c1e5beb9..6825bf687d 100644 --- a/frontend/resources/translations/en.json +++ b/frontend/resources/translations/en.json @@ -2054,6 +2054,7 @@ "containsPublishedPage": "This page contains one or more published page, it will be unpublished if you continue.", "publishSuccessfully": "Published successfully", "unpublishSuccessfully": "Unpublished successfully", - "publishFailed": "Failed to publish" + "publishFailed": "Failed to publish", + "unpublishFailed": "Failed to unpublish" } }