feat: show unpublish error

This commit is contained in:
Lucas.Xu 2024-07-03 11:05:15 +08:00
parent 59b36f67c8
commit 4ece2ff959
4 changed files with 51 additions and 16 deletions

View File

@ -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<DocumentShareEvent, DocumentShareState> {
@ -80,6 +81,7 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
state.copyWith(
isPublished: true,
publishResult: FlowySuccess(null),
unpublishResult: null,
url: '$_url/${result.namespace}/$publishName',
),
);
@ -92,12 +94,20 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
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<DocumentShareEvent, DocumentShareState> {
state.copyWith(
isPublished: isPublished,
publishResult: null,
url: '',
unpublishResult: result,
url: result.fold((_) => '', (_) => state.url),
),
);
},
@ -213,6 +224,7 @@ class DocumentShareState with _$DocumentShareState {
FlowyResult<ExportDataPB, FlowyError>? exportResult,
required bool isPublished,
FlowyResult<void, FlowyError>? publishResult,
FlowyResult<void, FlowyError>? unpublishResult,
required String url,
required String viewName,
}) = _DocumentShareState;

View File

@ -22,19 +22,7 @@ class PublishTab extends StatelessWidget {
Widget build(BuildContext context) {
return BlocConsumer<DocumentShareBloc, DocumentShareState>(
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 {

View File

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

View File

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