diff --git a/lib/common/actions/notes/delete.dart b/lib/common/actions/notes/delete.dart index 26b2bd26..25937d97 100644 --- a/lib/common/actions/notes/delete.dart +++ b/lib/common/actions/notes/delete.dart @@ -9,7 +9,6 @@ import '../../constants/constants.dart'; import '../../dialogs/confirmation_dialog.dart'; import '../../extensions/build_context_extension.dart'; import '../../ui/snack_bar_utils.dart'; -import 'archive.dart'; import 'restore.dart'; import 'select.dart'; @@ -50,7 +49,7 @@ Future deleteNote( context, text: context.l.snack_bar_deleted(1), onCancel: (globalRef) async => wasArchived - ? await archiveNote(rootNavigatorKey.currentContext!, globalRef, note: note, cancel: false) + ? await _restoreArchivedNotes(globalRef, [note]) : await restoreNote(rootNavigatorKey.currentContext!, globalRef, note: note, cancel: false), ); } @@ -86,7 +85,7 @@ Future deleteNotes(BuildContext context, WidgetRef ref, {required List wereArchived - ? await archiveNotes(rootNavigatorKey.currentContext!, globalRef, notes: notes, cancel: false) + ? await _restoreArchivedNotes(globalRef, notes) : await restoreNotes(rootNavigatorKey.currentContext!, globalRef, notes: notes, cancel: false), ); } @@ -94,6 +93,17 @@ Future deleteNotes(BuildContext context, WidgetRef ref, {required List _restoreArchivedNotes(WidgetRef ref, List notes) async { + if (!await ref.read(notesProvider(status: NoteStatus.deleted).notifier).setDeleted(notes, false)) { + return false; + } + + return ref.read(notesProvider(status: NoteStatus.available).notifier).setArchived(notes, true); +} + /// Permanently deletes the [note]. /// /// Returns `true` if the [note] was permanently deleted, `false` otherwise. diff --git a/lib/common/navigation/app_bars/notes/editor_app_bar.dart b/lib/common/navigation/app_bars/notes/editor_app_bar.dart index bc1a7a57..3db35281 100644 --- a/lib/common/navigation/app_bars/notes/editor_app_bar.dart +++ b/lib/common/navigation/app_bars/notes/editor_app_bar.dart @@ -91,6 +91,8 @@ class _BackAppBarState extends ConsumerState { await selectLabels(context, ref, note: note); case EditorArchivedMenuOption.unarchive: await unarchiveNote(context, ref, note: note, pop: true); + case EditorArchivedMenuOption.delete: + await deleteNote(context, ref, note: note, pop: true); case EditorArchivedMenuOption.about: await showAboutNote(); } @@ -221,6 +223,7 @@ class _BackAppBarState extends ConsumerState { EditorArchivedMenuOption.share.popupMenuItem(context), const PopupMenuDivider(), EditorArchivedMenuOption.unarchive.popupMenuItem(context), + EditorArchivedMenuOption.delete.popupMenuItem(context), const PopupMenuDivider(), EditorArchivedMenuOption.about.popupMenuItem(context), ]), diff --git a/lib/common/navigation/app_bars/selection/notes_selection_app_bar.dart b/lib/common/navigation/app_bars/selection/notes_selection_app_bar.dart index a41624d7..8caafe3b 100644 --- a/lib/common/navigation/app_bars/selection/notes_selection_app_bar.dart +++ b/lib/common/navigation/app_bars/selection/notes_selection_app_bar.dart @@ -74,6 +74,8 @@ class NotesSelectionAppBar extends ConsumerWidget { await shareNotes(context, notes: notes); case SelectionArchivedMenuOption.unarchive: await unarchiveNotes(context, ref, notes: notes); + case SelectionArchivedMenuOption.delete: + await deleteNotes(context, ref, notes: notes); } } @@ -136,6 +138,7 @@ class NotesSelectionAppBar extends ConsumerWidget { SelectionArchivedMenuOption.share.popupMenuItem(context), const PopupMenuDivider(), SelectionArchivedMenuOption.unarchive.popupMenuItem(context), + SelectionArchivedMenuOption.delete.popupMenuItem(context), ]), onSelected: (menuOption) => onArchivedMenuOptionSelected(context, ref, selectedNotes, menuOption), ), diff --git a/lib/common/navigation/enums/editor/editor_archived_menu_option.dart b/lib/common/navigation/enums/editor/editor_archived_menu_option.dart index 74b754ec..9b8b69d0 100644 --- a/lib/common/navigation/enums/editor/editor_archived_menu_option.dart +++ b/lib/common/navigation/enums/editor/editor_archived_menu_option.dart @@ -16,6 +16,9 @@ enum EditorArchivedMenuOption { /// Unarchive the note. unarchive(Icons.unarchive), + /// Delete the note. + delete(Icons.delete), + /// Show information about the note. about(Icons.info); @@ -36,6 +39,8 @@ enum EditorArchivedMenuOption { return context.l.menu_action_select_labels; case unarchive: return context.l.action_unarchive; + case delete: + return context.l.action_delete; case about: return context.l.action_about; } diff --git a/lib/common/navigation/enums/notes/selection_archived_menu_option.dart b/lib/common/navigation/enums/notes/selection_archived_menu_option.dart index 8cbe5bfe..8465cdca 100644 --- a/lib/common/navigation/enums/notes/selection_archived_menu_option.dart +++ b/lib/common/navigation/enums/notes/selection_archived_menu_option.dart @@ -11,7 +11,10 @@ enum SelectionArchivedMenuOption { share(Icons.share), /// Unarchive the note. - unarchive(Icons.unarchive); + unarchive(Icons.unarchive), + + /// Delete the notes. + delete(Icons.delete); /// Icon of the menu option. final IconData icon; @@ -30,6 +33,8 @@ enum SelectionArchivedMenuOption { return context.fl.shareButtonLabel; case unarchive: return context.l.action_unarchive; + case delete: + return context.l.action_delete; } }