mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: show a confirm deletion dialog if the deleted page contains published page
This commit is contained in:
parent
2da3744700
commit
cb2a7c9f98
@ -1,6 +1,6 @@
|
||||
String replaceInvalidChars(String input) {
|
||||
final RegExp invalidCharsRegex = RegExp('[^a-zA-Z0-9-]');
|
||||
return input.replaceAll(invalidCharsRegex, '');
|
||||
return input.replaceAll(invalidCharsRegex, '-');
|
||||
}
|
||||
|
||||
Future<String> generateNameSpace() async {
|
||||
|
@ -1,13 +1,16 @@
|
||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/plugins/document/application/document_share_bloc.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/share/pubish_color_extension.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/share/publish_name_generator.dart';
|
||||
import 'package:appflowy/startup/startup.dart';
|
||||
import 'package:appflowy/util/theme_extension.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/toast.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
||||
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@ -99,7 +102,9 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
|
||||
_PublishUrl(
|
||||
controller: controller,
|
||||
onCopy: (url) {
|
||||
AppFlowyClipboard.setData(text: url);
|
||||
getIt<ClipboardService>().setData(
|
||||
ClipboardServiceData(plainText: url),
|
||||
);
|
||||
},
|
||||
onSubmitted: (url) {},
|
||||
),
|
||||
@ -242,8 +247,7 @@ class _PublishUrl extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildCopyLinkIcon(BuildContext context) {
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
return FlowyHover(
|
||||
child: GestureDetector(
|
||||
onTap: () => onCopy(controller.text),
|
||||
child: Container(
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:appflowy/core/config/kv.dart';
|
||||
@ -141,8 +142,14 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
|
||||
final result = await ViewBackendService.delete(viewId: view.id);
|
||||
emit(
|
||||
result.fold(
|
||||
(l) =>
|
||||
state.copyWith(successOrFailure: FlowyResult.success(null)),
|
||||
(l) {
|
||||
// unpublish the page if it's published
|
||||
unawaited(_unpublishPage(view));
|
||||
|
||||
return state.copyWith(
|
||||
successOrFailure: FlowyResult.success(null),
|
||||
);
|
||||
},
|
||||
(error) => state.copyWith(
|
||||
successOrFailure: FlowyResult.failure(error),
|
||||
),
|
||||
@ -383,6 +390,37 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _unpublishPage(ViewPB view) async {
|
||||
final allChildViews = await _getAllChildViews(view);
|
||||
final views = [view, ...allChildViews];
|
||||
|
||||
// unpublish
|
||||
for (final view in views) {
|
||||
await ViewBackendService.unpublish(view);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ViewPB>> _getAllChildViews(ViewPB view) async {
|
||||
final views = <ViewPB>[];
|
||||
|
||||
final childViews =
|
||||
await ViewBackendService.getChildViews(viewId: view.id).fold(
|
||||
(s) => s,
|
||||
(f) => [],
|
||||
);
|
||||
|
||||
for (final child in childViews) {
|
||||
// filter the view itself
|
||||
if (child.id == view.id) {
|
||||
continue;
|
||||
}
|
||||
views.add(child);
|
||||
views.addAll(await _getAllChildViews(child));
|
||||
}
|
||||
|
||||
return views;
|
||||
}
|
||||
|
||||
bool _isSameViewIgnoreChildren(ViewPB from, ViewPB to) {
|
||||
return _hash(from) == _hash(to);
|
||||
}
|
||||
|
@ -329,4 +329,25 @@ class ViewBackendService {
|
||||
getPublishNameSpace() async {
|
||||
return FolderEventGetPublishNamespace().send();
|
||||
}
|
||||
|
||||
static Future<List<ViewPB>> getAllChildViews(ViewPB view) async {
|
||||
final views = <ViewPB>[];
|
||||
|
||||
final childViews =
|
||||
await ViewBackendService.getChildViews(viewId: view.id).fold(
|
||||
(s) => s,
|
||||
(f) => [],
|
||||
);
|
||||
|
||||
for (final child in childViews) {
|
||||
// filter the view itself
|
||||
if (child.id == view.id) {
|
||||
continue;
|
||||
}
|
||||
views.add(child);
|
||||
views.addAll(await getAllChildViews(child));
|
||||
}
|
||||
|
||||
return views;
|
||||
}
|
||||
}
|
||||
|
@ -222,13 +222,20 @@ class SpaceCancelOrConfirmButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteSpacePopup extends StatelessWidget {
|
||||
const DeleteSpacePopup({super.key});
|
||||
class ConfirmDeletionPopup extends StatelessWidget {
|
||||
const ConfirmDeletionPopup({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.onConfirm,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String description;
|
||||
final VoidCallback onConfirm;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final space = context.read<SpaceBloc>().state.currentSpace;
|
||||
final name = space != null ? space.name : '';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 20.0,
|
||||
@ -241,7 +248,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
FlowyText(
|
||||
LocaleKeys.space_deleteConfirmation.tr() + name,
|
||||
title,
|
||||
fontSize: 14.0,
|
||||
),
|
||||
const Spacer(),
|
||||
@ -254,7 +261,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
||||
),
|
||||
const VSpace(8.0),
|
||||
FlowyText.regular(
|
||||
LocaleKeys.space_deleteConfirmationDescription.tr(),
|
||||
description,
|
||||
fontSize: 12.0,
|
||||
color: Theme.of(context).hintColor,
|
||||
maxLines: 3,
|
||||
@ -264,7 +271,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
||||
SpaceCancelOrConfirmButton(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () {
|
||||
context.read<SpaceBloc>().add(const SpaceEvent.delete(null));
|
||||
onConfirm();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmButtonName: LocaleKeys.space_delete.tr(),
|
||||
|
@ -230,13 +230,26 @@ class _SidebarSpaceHeaderState extends State<SidebarSpaceHeader> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
final space = spaceBloc.state.currentSpace;
|
||||
final name = space != null ? space.name : '';
|
||||
final title = LocaleKeys.space_deleteConfirmation.tr() + name;
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: BlocProvider.value(
|
||||
value: spaceBloc,
|
||||
child: const SizedBox(width: 440, child: DeleteSpacePopup()),
|
||||
child: SizedBox(
|
||||
width: 440,
|
||||
child: ConfirmDeletionPopup(
|
||||
title: title,
|
||||
description:
|
||||
LocaleKeys.space_deleteConfirmationDescription.tr(),
|
||||
onConfirm: () {
|
||||
context.read<SpaceBloc>().add(const SpaceEvent.delete(null));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/plugins/base/icon/icon_picker.dart';
|
||||
@ -11,6 +13,7 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/draggable_view_item.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_add_button.dart';
|
||||
@ -690,7 +693,7 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
spaceType: widget.spaceType,
|
||||
onEditing: (value) =>
|
||||
context.read<ViewBloc>().add(ViewEvent.setIsEditing(value)),
|
||||
onAction: (action, data) {
|
||||
onAction: (action, data) async {
|
||||
switch (action) {
|
||||
case ViewMoreActionType.favorite:
|
||||
case ViewMoreActionType.unFavorite:
|
||||
@ -699,18 +702,31 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
.add(FavoriteEvent.toggle(widget.view));
|
||||
break;
|
||||
case ViewMoreActionType.rename:
|
||||
NavigatorTextFieldDialog(
|
||||
title: LocaleKeys.disclosureAction_rename.tr(),
|
||||
autoSelectAllText: true,
|
||||
value: widget.view.name,
|
||||
maxLength: 256,
|
||||
onConfirm: (newValue, _) {
|
||||
context.read<ViewBloc>().add(ViewEvent.rename(newValue));
|
||||
},
|
||||
).show(context);
|
||||
unawaited(
|
||||
NavigatorTextFieldDialog(
|
||||
title: LocaleKeys.disclosureAction_rename.tr(),
|
||||
autoSelectAllText: true,
|
||||
value: widget.view.name,
|
||||
maxLength: 256,
|
||||
onConfirm: (newValue, _) {
|
||||
context.read<ViewBloc>().add(ViewEvent.rename(newValue));
|
||||
},
|
||||
).show(context),
|
||||
);
|
||||
break;
|
||||
case ViewMoreActionType.delete:
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
// get if current page contains published child views
|
||||
final childViews =
|
||||
await ViewBackendService.getAllChildViews(widget.view);
|
||||
final views = [widget.view, ...childViews];
|
||||
final containPublishedPage = await Future.wait(
|
||||
views.map((e) => ViewBackendService.getPublishInfo(e)),
|
||||
).then((value) => value.where((e) => e.isSuccess));
|
||||
if (containPublishedPage.isNotEmpty && context.mounted) {
|
||||
_showDeleteDialog(context);
|
||||
} else if (context.mounted) {
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
}
|
||||
break;
|
||||
case ViewMoreActionType.duplicate:
|
||||
context.read<ViewBloc>().add(const ViewEvent.duplicate());
|
||||
@ -726,7 +742,7 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
return;
|
||||
}
|
||||
final result = data;
|
||||
ViewBackendService.updateViewIcon(
|
||||
await ViewBackendService.updateViewIcon(
|
||||
viewId: widget.view.id,
|
||||
viewIcon: result.emoji,
|
||||
iconType: result.type.toProto(),
|
||||
@ -737,9 +753,6 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
if (target is! ViewPB) {
|
||||
return;
|
||||
}
|
||||
debugPrint(
|
||||
'Move view ${widget.view.id}, ${widget.view.name} to ${target.id}, ${target.name}',
|
||||
);
|
||||
_moveViewCrossSection(
|
||||
context,
|
||||
widget.view,
|
||||
@ -771,6 +784,30 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
}
|
||||
return LocaleKeys.newPageText.tr();
|
||||
}
|
||||
|
||||
void _showDeleteDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 440,
|
||||
child: ConfirmDeletionPopup(
|
||||
title:
|
||||
LocaleKeys.space_deleteConfirmation.tr() + widget.view.name,
|
||||
description: LocaleKeys.publish_containsPublishedPage.tr(),
|
||||
onConfirm: () {
|
||||
context.read<ViewBloc>().add(const ViewEvent.delete());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DotIconWidget extends StatelessWidget {
|
||||
|
@ -957,6 +957,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
iconsax_flutter:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: iconsax_flutter
|
||||
sha256: "95b65699da8ea98f87c5d232f06b0debaaf1ec1332b697e4d90969ec9a93037d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
image_gallery_saver:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -1418,6 +1426,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
pausable_timer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pausable_timer
|
||||
sha256: "6ef1a95441ec3439de6fb63f39a011b67e693198e7dae14e20675c3c00e86074"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0+3"
|
||||
percent_indicator:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -2057,6 +2073,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
toastification:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: toastification
|
||||
sha256: "5e751acc2fb5b8d008138dac255d62290fde4e5a24824f29809ac098c3dfe395"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -150,6 +150,7 @@ dependencies:
|
||||
|
||||
flutter_highlight: ^0.7.0
|
||||
custom_sliding_segmented_control: ^1.8.3
|
||||
toastification: ^2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_lints: ^3.0.1
|
||||
|
@ -2050,6 +2050,7 @@
|
||||
"codeBlock": "The content of code block has been copied to the clipboard",
|
||||
"imageBlock": "The image link has been copied to the clipboard",
|
||||
"mathBlock": "The math equation has been copied to the clipboard"
|
||||
}
|
||||
},
|
||||
"containsPublishedPage": "This page contains one or more published page, it will be unpublished if you continue."
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user