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) {
|
String replaceInvalidChars(String input) {
|
||||||
final RegExp invalidCharsRegex = RegExp('[^a-zA-Z0-9-]');
|
final RegExp invalidCharsRegex = RegExp('[^a-zA-Z0-9-]');
|
||||||
return input.replaceAll(invalidCharsRegex, '');
|
return input.replaceAll(invalidCharsRegex, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> generateNameSpace() async {
|
Future<String> generateNameSpace() async {
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.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/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/pubish_color_extension.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/share/publish_name_generator.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/util/theme_extension.dart';
|
||||||
import 'package:appflowy/workspace/presentation/home/toast.dart';
|
import 'package:appflowy/workspace/presentation/home/toast.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.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:flowy_infra_ui/widget/rounded_button.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
@ -99,7 +102,9 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
|
|||||||
_PublishUrl(
|
_PublishUrl(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
onCopy: (url) {
|
onCopy: (url) {
|
||||||
AppFlowyClipboard.setData(text: url);
|
getIt<ClipboardService>().setData(
|
||||||
|
ClipboardServiceData(plainText: url),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
onSubmitted: (url) {},
|
onSubmitted: (url) {},
|
||||||
),
|
),
|
||||||
@ -242,8 +247,7 @@ class _PublishUrl extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCopyLinkIcon(BuildContext context) {
|
Widget _buildCopyLinkIcon(BuildContext context) {
|
||||||
return MouseRegion(
|
return FlowyHover(
|
||||||
cursor: SystemMouseCursors.click,
|
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => onCopy(controller.text),
|
onTap: () => onCopy(controller.text),
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:appflowy/core/config/kv.dart';
|
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);
|
final result = await ViewBackendService.delete(viewId: view.id);
|
||||||
emit(
|
emit(
|
||||||
result.fold(
|
result.fold(
|
||||||
(l) =>
|
(l) {
|
||||||
state.copyWith(successOrFailure: FlowyResult.success(null)),
|
// unpublish the page if it's published
|
||||||
|
unawaited(_unpublishPage(view));
|
||||||
|
|
||||||
|
return state.copyWith(
|
||||||
|
successOrFailure: FlowyResult.success(null),
|
||||||
|
);
|
||||||
|
},
|
||||||
(error) => state.copyWith(
|
(error) => state.copyWith(
|
||||||
successOrFailure: FlowyResult.failure(error),
|
successOrFailure: FlowyResult.failure(error),
|
||||||
),
|
),
|
||||||
@ -383,6 +390,37 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
|
|||||||
return null;
|
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) {
|
bool _isSameViewIgnoreChildren(ViewPB from, ViewPB to) {
|
||||||
return _hash(from) == _hash(to);
|
return _hash(from) == _hash(to);
|
||||||
}
|
}
|
||||||
|
@ -329,4 +329,25 @@ class ViewBackendService {
|
|||||||
getPublishNameSpace() async {
|
getPublishNameSpace() async {
|
||||||
return FolderEventGetPublishNamespace().send();
|
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 {
|
class ConfirmDeletionPopup extends StatelessWidget {
|
||||||
const DeleteSpacePopup({super.key});
|
const ConfirmDeletionPopup({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.description,
|
||||||
|
required this.onConfirm,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final String description;
|
||||||
|
final VoidCallback onConfirm;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final space = context.read<SpaceBloc>().state.currentSpace;
|
|
||||||
final name = space != null ? space.name : '';
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 20.0,
|
vertical: 20.0,
|
||||||
@ -241,7 +248,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
FlowyText(
|
FlowyText(
|
||||||
LocaleKeys.space_deleteConfirmation.tr() + name,
|
title,
|
||||||
fontSize: 14.0,
|
fontSize: 14.0,
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
@ -254,7 +261,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const VSpace(8.0),
|
const VSpace(8.0),
|
||||||
FlowyText.regular(
|
FlowyText.regular(
|
||||||
LocaleKeys.space_deleteConfirmationDescription.tr(),
|
description,
|
||||||
fontSize: 12.0,
|
fontSize: 12.0,
|
||||||
color: Theme.of(context).hintColor,
|
color: Theme.of(context).hintColor,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
@ -264,7 +271,7 @@ class DeleteSpacePopup extends StatelessWidget {
|
|||||||
SpaceCancelOrConfirmButton(
|
SpaceCancelOrConfirmButton(
|
||||||
onCancel: () => Navigator.of(context).pop(),
|
onCancel: () => Navigator.of(context).pop(),
|
||||||
onConfirm: () {
|
onConfirm: () {
|
||||||
context.read<SpaceBloc>().add(const SpaceEvent.delete(null));
|
onConfirm();
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
confirmButtonName: LocaleKeys.space_delete.tr(),
|
confirmButtonName: LocaleKeys.space_delete.tr(),
|
||||||
|
@ -230,13 +230,26 @@ class _SidebarSpaceHeaderState extends State<SidebarSpaceHeader> {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) {
|
builder: (_) {
|
||||||
|
final space = spaceBloc.state.currentSpace;
|
||||||
|
final name = space != null ? space.name : '';
|
||||||
|
final title = LocaleKeys.space_deleteConfirmation.tr() + name;
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12.0),
|
borderRadius: BorderRadius.circular(12.0),
|
||||||
),
|
),
|
||||||
child: BlocProvider.value(
|
child: BlocProvider.value(
|
||||||
value: spaceBloc,
|
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/flowy_svgs.g.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/base/icon/icon_picker.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/home_sizes.dart';
|
||||||
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.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/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/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_action_type.dart';
|
||||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_add_button.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,
|
spaceType: widget.spaceType,
|
||||||
onEditing: (value) =>
|
onEditing: (value) =>
|
||||||
context.read<ViewBloc>().add(ViewEvent.setIsEditing(value)),
|
context.read<ViewBloc>().add(ViewEvent.setIsEditing(value)),
|
||||||
onAction: (action, data) {
|
onAction: (action, data) async {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ViewMoreActionType.favorite:
|
case ViewMoreActionType.favorite:
|
||||||
case ViewMoreActionType.unFavorite:
|
case ViewMoreActionType.unFavorite:
|
||||||
@ -699,18 +702,31 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
|||||||
.add(FavoriteEvent.toggle(widget.view));
|
.add(FavoriteEvent.toggle(widget.view));
|
||||||
break;
|
break;
|
||||||
case ViewMoreActionType.rename:
|
case ViewMoreActionType.rename:
|
||||||
NavigatorTextFieldDialog(
|
unawaited(
|
||||||
title: LocaleKeys.disclosureAction_rename.tr(),
|
NavigatorTextFieldDialog(
|
||||||
autoSelectAllText: true,
|
title: LocaleKeys.disclosureAction_rename.tr(),
|
||||||
value: widget.view.name,
|
autoSelectAllText: true,
|
||||||
maxLength: 256,
|
value: widget.view.name,
|
||||||
onConfirm: (newValue, _) {
|
maxLength: 256,
|
||||||
context.read<ViewBloc>().add(ViewEvent.rename(newValue));
|
onConfirm: (newValue, _) {
|
||||||
},
|
context.read<ViewBloc>().add(ViewEvent.rename(newValue));
|
||||||
).show(context);
|
},
|
||||||
|
).show(context),
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case ViewMoreActionType.delete:
|
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;
|
break;
|
||||||
case ViewMoreActionType.duplicate:
|
case ViewMoreActionType.duplicate:
|
||||||
context.read<ViewBloc>().add(const ViewEvent.duplicate());
|
context.read<ViewBloc>().add(const ViewEvent.duplicate());
|
||||||
@ -726,7 +742,7 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final result = data;
|
final result = data;
|
||||||
ViewBackendService.updateViewIcon(
|
await ViewBackendService.updateViewIcon(
|
||||||
viewId: widget.view.id,
|
viewId: widget.view.id,
|
||||||
viewIcon: result.emoji,
|
viewIcon: result.emoji,
|
||||||
iconType: result.type.toProto(),
|
iconType: result.type.toProto(),
|
||||||
@ -737,9 +753,6 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
|||||||
if (target is! ViewPB) {
|
if (target is! ViewPB) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debugPrint(
|
|
||||||
'Move view ${widget.view.id}, ${widget.view.name} to ${target.id}, ${target.name}',
|
|
||||||
);
|
|
||||||
_moveViewCrossSection(
|
_moveViewCrossSection(
|
||||||
context,
|
context,
|
||||||
widget.view,
|
widget.view,
|
||||||
@ -771,6 +784,30 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
|||||||
}
|
}
|
||||||
return LocaleKeys.newPageText.tr();
|
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 {
|
class _DotIconWidget extends StatelessWidget {
|
||||||
|
@ -957,6 +957,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.2"
|
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:
|
image_gallery_saver:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -1418,6 +1426,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.1"
|
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:
|
percent_indicator:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -2057,6 +2073,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
|
toastification:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: toastification
|
||||||
|
sha256: "5e751acc2fb5b8d008138dac255d62290fde4e5a24824f29809ac098c3dfe395"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
tuple:
|
tuple:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -150,6 +150,7 @@ dependencies:
|
|||||||
|
|
||||||
flutter_highlight: ^0.7.0
|
flutter_highlight: ^0.7.0
|
||||||
custom_sliding_segmented_control: ^1.8.3
|
custom_sliding_segmented_control: ^1.8.3
|
||||||
|
toastification: ^2.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^3.0.1
|
flutter_lints: ^3.0.1
|
||||||
|
@ -2050,6 +2050,7 @@
|
|||||||
"codeBlock": "The content of code block has been copied to the clipboard",
|
"codeBlock": "The content of code block has been copied to the clipboard",
|
||||||
"imageBlock": "The image link 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"
|
"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