diff --git a/lib/common/actions/notes/archive.dart b/lib/common/actions/notes/archive.dart index 815d3f93..bf26ab29 100644 --- a/lib/common/actions/notes/archive.dart +++ b/lib/common/actions/notes/archive.dart @@ -15,11 +15,7 @@ import 'select.dart'; /// /// First, asks for a confirmation if needed. /// Finally, pops the route if the note was archived from the editor page. -Future archiveNote(BuildContext context, WidgetRef ref, {Note? note, bool pop = false}) async { - if (note == null) { - return false; - } - +Future archiveNote(BuildContext context, WidgetRef ref, {required Note note, bool pop = false}) async { if (!await askForConfirmation( context, l.dialog_archive, diff --git a/lib/common/actions/notes/unarchive.dart b/lib/common/actions/notes/unarchive.dart index 681e1805..4491bed0 100644 --- a/lib/common/actions/notes/unarchive.dart +++ b/lib/common/actions/notes/unarchive.dart @@ -15,11 +15,7 @@ import 'select.dart'; /// /// First, asks for a confirmation if needed. /// Finally, pops the route if the note was unarchived from the editor page. -Future unarchiveNote(BuildContext context, WidgetRef ref, {Note? note, bool pop = false}) async { - if (note == null) { - return false; - } - +Future unarchiveNote(BuildContext context, WidgetRef ref, {required Note note, bool pop = false}) async { if (!await askForConfirmation( context, l.dialog_unarchive, diff --git a/lib/common/navigation/app_bars/editor_app_bar.dart b/lib/common/navigation/app_bars/editor_app_bar.dart index 5c6a6192..49a2b574 100644 --- a/lib/common/navigation/app_bars/editor_app_bar.dart +++ b/lib/common/navigation/app_bars/editor_app_bar.dart @@ -18,6 +18,7 @@ import '../../constants/constants.dart'; import '../../constants/paddings.dart'; import '../../preferences/preference_key.dart'; import '../../utils.dart'; +import '../../widgets/placeholders/empty_placeholder.dart'; import '../enums/archives_menu_option.dart'; import '../enums/bin_menu_option.dart'; import '../enums/editor_menu_option.dart'; @@ -58,7 +59,7 @@ class _BackAppBarState extends ConsumerState { case EditorMenuOption.share: await shareNote(note: note); case EditorMenuOption.archive: - await archiveNote(context, ref); + await archiveNote(context, ref, note: note); case EditorMenuOption.delete: await deleteNote(context, ref, note: note, pop: true); case EditorMenuOption.about: @@ -145,7 +146,7 @@ class _BackAppBarState extends ConsumerState { final note = currentNoteNotifier.value; if (note == null) { - return SizedBox.shrink(); + return EmptyPlaceholder(); } final editorController = fleatherControllerNotifier.value; diff --git a/lib/common/navigation/app_bars/notes_selection_app_bar.dart b/lib/common/navigation/app_bars/notes_selection_app_bar.dart index fc152f61..1dd86732 100644 --- a/lib/common/navigation/app_bars/notes_selection_app_bar.dart +++ b/lib/common/navigation/app_bars/notes_selection_app_bar.dart @@ -50,9 +50,9 @@ class NotesSelectionAppBar extends ConsumerWidget { case NotesMenuOption.togglePin: await togglePinNotes(context, ref, notes: notes); case NotesMenuOption.addLabels: - addLabels(context, ref, notes: notes); + await addLabels(context, ref, notes: notes); case NotesMenuOption.archive: - await archiveNote(context, ref); + await archiveNotes(context, ref, notes: notes); case NotesMenuOption.delete: await deleteNotes(context, ref, notes: notes); } diff --git a/lib/common/navigation/side_navigation.dart b/lib/common/navigation/side_navigation.dart index b93695c8..ba1c875d 100644 --- a/lib/common/navigation/side_navigation.dart +++ b/lib/common/navigation/side_navigation.dart @@ -5,6 +5,7 @@ import 'package:material_symbols_icons/material_symbols_icons.dart'; import '../../models/label/label.dart'; import '../../navigation/navigation_routes.dart'; import '../../navigation/navigator_utils.dart'; +import '../../pages/archives/archives_page.dart'; import '../../pages/bin/bin_page.dart'; import '../../pages/labels/labels_page.dart'; import '../../pages/notes/notes_page.dart'; @@ -63,10 +64,12 @@ class _SideNavigationState extends ConsumerState { index = labels.indexOf(label) + 1; } else if (route == NavigationRoute.manageLabels.name) { index = labels.length + 1; - } else if (route == NavigationRoute.bin.name) { + } else if (route == NavigationRoute.archives.name) { index = labels.length + 2; - } else if (route == NavigationRoute.settings.name) { + } else if (route == NavigationRoute.bin.name) { index = labels.length + 3; + } else if (route == NavigationRoute.settings.name) { + index = labels.length + 4; } else { throw Exception('Unknown route while setting the index of the navigation drawer: $route'); } @@ -76,10 +79,12 @@ class _SideNavigationState extends ConsumerState { else { if (route == '/' || route == NavigationRoute.notes.name) { index = 0; - } else if (route == NavigationRoute.bin.name) { + } else if (route == NavigationRoute.archives.name) { index = 1; - } else if (route == NavigationRoute.settings.name) { + } else if (route == NavigationRoute.bin.name) { index = 2; + } else if (route == NavigationRoute.settings.name) { + index = 3; } else { throw Exception('Unknown route while setting the index of the navigation drawer: $route'); } @@ -134,8 +139,10 @@ class _SideNavigationState extends ConsumerState { } else if (index == labels.length + 1) { NavigationRoute.manageLabels.pushOrGo(context, isHomeRoute(route), LabelsPage()); } else if (index == labels.length + 2) { - NavigationRoute.bin.pushOrGo(context, isHomeRoute(route), BinPage()); + NavigationRoute.archives.pushOrGo(context, isHomeRoute(route), ArchivesPage()); } else if (index == labels.length + 3) { + NavigationRoute.bin.pushOrGo(context, isHomeRoute(route), BinPage()); + } else if (index == labels.length + 4) { NavigationRoute.settings.pushOrGo(context, isHomeRoute(route), SettingsMainPage()); } else { throw Exception('Invalid drawer index while navigating to a new route: $index'); @@ -219,12 +226,16 @@ class _SideNavigationState extends ConsumerState { Divider(indent: 24, endIndent: 24), ], NavigationDrawerDestination( - key: Keys.drawerNotesTab, + icon: const Icon(Icons.archive_outlined), + selectedIcon: const Icon(Icons.archive), + label: Text(l.navigation_archives), + ), + NavigationDrawerDestination( icon: const Icon(Icons.delete_outline), selectedIcon: const Icon(Icons.delete), label: Text(l.navigation_bin), ), - // Divider(indent: 24, endIndent: 24), + Divider(indent: 24, endIndent: 24), NavigationDrawerDestination( key: Keys.drawerSettingsTab, icon: const Icon(Icons.settings_outlined), diff --git a/lib/common/widgets/placeholders/empty_placeholder.dart b/lib/common/widgets/placeholders/empty_placeholder.dart index 1ae8d8cc..b5c3f67f 100644 --- a/lib/common/widgets/placeholders/empty_placeholder.dart +++ b/lib/common/widgets/placeholders/empty_placeholder.dart @@ -19,7 +19,7 @@ class EmptyPlaceholder extends StatelessWidget { /// Empty archived notes list. EmptyPlaceholder.archived({super.key}) : icon = Icons.archive_outlined, - text = l.placeholder_bin; + text = l.placeholder_archives; /// Empty deleted notes list. EmptyPlaceholder.deleted({super.key}) diff --git a/lib/l10n/translations/app_en.arb b/lib/l10n/translations/app_en.arb index eb1be5ad..9465a635 100644 --- a/lib/l10n/translations/app_en.arb +++ b/lib/l10n/translations/app_en.arb @@ -939,9 +939,13 @@ "@placeholder_labels": { "description": "Placeholder on the labels page when there are no labels." }, + "placeholder_archives": "No archived notes", + "@placeholder_archives": { + "description": "Placeholder on the archives notes page when there are no archived notes." + }, "placeholder_bin": "No deleted notes", "@placeholder_bin": { - "description": "Placeholder on the bin page when there are no notes." + "description": "Placeholder on the bin page when there are no deleted notes." }, "action_disabled": "Disabled", "@action_disabled": { diff --git a/lib/models/note/note_status.dart b/lib/models/note/note_status.dart index d9077986..019ce398 100644 --- a/lib/models/note/note_status.dart +++ b/lib/models/note/note_status.dart @@ -9,7 +9,4 @@ enum NoteStatus { /// The note is deleted. deleted, ; - - /// Returns the list of status where the note can be edited. - static List get editable => [available, archived]; } diff --git a/lib/navigation/navigation_routes.dart b/lib/navigation/navigation_routes.dart index 615236ef..f74d7598 100644 --- a/lib/navigation/navigation_routes.dart +++ b/lib/navigation/navigation_routes.dart @@ -14,6 +14,9 @@ enum NavigationRoute { manageLabels, label, + // Archives + archives, + // Bin bin, diff --git a/lib/pages/archives/archives_page.dart b/lib/pages/archives/archives_page.dart new file mode 100644 index 00000000..485fe86a --- /dev/null +++ b/lib/pages/archives/archives_page.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../common/navigation/app_bars/notes_app_bar.dart'; +import '../../common/navigation/side_navigation.dart'; +import '../../common/navigation/top_navigation.dart'; +import '../../common/widgets/notes/notes_list.dart'; +import '../../models/note/note_status.dart'; + +/// List of archived notes. +class ArchivesPage extends ConsumerStatefulWidget { + /// Default constructor. + const ArchivesPage({super.key}); + + @override + ConsumerState createState() => _ArchivesPageState(); +} + +class _ArchivesPageState extends ConsumerState { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: TopNavigation( + appbar: NotesAppBar(notesStatus: NoteStatus.archived), + notesStatus: NoteStatus.archived, + ), + drawer: SideNavigation(), + body: NotesList(notesStatus: NoteStatus.archived), + ); + } +} diff --git a/lib/pages/bin/bin_page.dart b/lib/pages/bin/bin_page.dart index 793005a1..d4b749df 100644 --- a/lib/pages/bin/bin_page.dart +++ b/lib/pages/bin/bin_page.dart @@ -4,16 +4,11 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../common/navigation/app_bars/notes_app_bar.dart'; import '../../common/navigation/side_navigation.dart'; import '../../common/navigation/top_navigation.dart'; -import '../../common/widgets/keys.dart'; import '../../common/widgets/notes/notes_list.dart'; import '../../models/note/note_status.dart'; import 'widgets/empty_bin_fab.dart'; -/// Page displaying the deleted notes. -/// -/// Contains: -/// - The list of deleted notes. -/// - The FAB to empty the bin. +/// List of deleted notes. class BinPage extends ConsumerStatefulWidget { /// Default constructor. const BinPage({super.key}); @@ -27,20 +22,12 @@ class _BinPageState extends ConsumerState { Widget build(BuildContext context) { return Scaffold( appBar: TopNavigation( - appbar: NotesAppBar( - key: Keys.appBarNotesBin, - notesStatus: NoteStatus.deleted, - ), + appbar: NotesAppBar(notesStatus: NoteStatus.deleted), notesStatus: NoteStatus.deleted, ), drawer: SideNavigation(), - floatingActionButton: EmptyBinFab( - key: Keys.fabEmptyBin, - ), - body: NotesList( - key: Keys.notesPageNotesList, - notesStatus: NoteStatus.deleted, - ), + floatingActionButton: EmptyBinFab(), + body: NotesList(notesStatus: NoteStatus.deleted), ); } } diff --git a/lib/pages/bin/widgets/empty_bin_fab.dart b/lib/pages/bin/widgets/empty_bin_fab.dart index bd07daad..ce2f8ac9 100644 --- a/lib/pages/bin/widgets/empty_bin_fab.dart +++ b/lib/pages/bin/widgets/empty_bin_fab.dart @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../common/actions/notes/delete.dart'; import '../../../common/constants/constants.dart'; +import '../../../common/widgets/placeholders/empty_placeholder.dart'; import '../../../models/note/note_status.dart'; import '../../../providers/notes/notes_provider.dart'; @@ -21,6 +22,6 @@ class EmptyBinFab extends ConsumerWidget { onPressed: () => emptyBin(context, ref), child: const Icon(Icons.delete_forever), ) - : SizedBox.shrink(); + : EmptyPlaceholder(); } } diff --git a/lib/pages/notes/notes_page.dart b/lib/pages/notes/notes_page.dart index 63f64cff..f25025e4 100644 --- a/lib/pages/notes/notes_page.dart +++ b/lib/pages/notes/notes_page.dart @@ -13,7 +13,7 @@ import '../../providers/notifiers/notifiers.dart'; import '../../providers/preferences/preferences_provider.dart'; import 'widgets/add_note_fab.dart'; -/// List of notes. +/// List of available notes. class NotesPage extends ConsumerStatefulWidget { /// The list of the notes and the FAB to add a new note. /// diff --git a/lib/providers/notes/notes_provider.dart b/lib/providers/notes/notes_provider.dart index e4d5284f..4ee2b3b7 100644 --- a/lib/providers/notes/notes_provider.dart +++ b/lib/providers/notes/notes_provider.dart @@ -55,7 +55,7 @@ class Notes extends _$Notes { /// /// The note can be forcefully put into the database even it it's empty using [forcePut]. Future edit(Note editedNote, {bool forcePut = false}) async { - _checkEditableStatus(); + _checkStatus([NoteStatus.available, NoteStatus.archived]); editedNote.editedTime = DateTime.now(); @@ -86,7 +86,7 @@ class Notes extends _$Notes { /// Saves the [note] with the new [selectedLabels] to the database. Future editLabels(Note note, Iterable