diff --git a/packages/neon/neon_notes/lib/options.dart b/packages/neon/neon_notes/lib/options.dart index 72c7cb26..f7ac1957 100644 --- a/packages/neon/neon_notes/lib/options.dart +++ b/packages/neon/neon_notes/lib/options.dart @@ -108,6 +108,7 @@ enum DefaultNoteViewType { enum NotesSortProperty { lastModified, alphabetical, + favorite, } enum CategoriesSortProperty { diff --git a/packages/neon/neon_notes/lib/sort/notes.dart b/packages/neon/neon_notes/lib/sort/notes.dart index 430bf0f9..bed700b2 100644 --- a/packages/neon/neon_notes/lib/sort/notes.dart +++ b/packages/neon/neon_notes/lib/sort/notes.dart @@ -4,10 +4,14 @@ final notesSortBox = SortBox( { NotesSortProperty.alphabetical: (final note) => note.title.toLowerCase(), NotesSortProperty.lastModified: (final note) => note.modified, + NotesSortProperty.favorite: (final note) => note.favorite ? 0 : 1, }, { NotesSortProperty.alphabetical: { (NotesSortProperty.lastModified, SortBoxOrder.descending), }, + NotesSortProperty.lastModified: { + (NotesSortProperty.alphabetical, SortBoxOrder.ascending), + }, }, ); diff --git a/packages/neon/neon_notes/lib/widgets/notes_view.dart b/packages/neon/neon_notes/lib/widgets/notes_view.dart index 3926f975..03ef7266 100644 --- a/packages/neon/neon_notes/lib/widgets/notes_view.dart +++ b/packages/neon/neon_notes/lib/widgets/notes_view.dart @@ -15,30 +15,20 @@ class NotesView extends StatelessWidget { stream: bloc.notes, builder: (final context, final notes) => SortBoxBuilder( sortBox: notesSortBox, + presort: const { + (NotesSortProperty.favorite, SortBoxOrder.ascending), + }, sortPropertyOption: bloc.options.notesSortPropertyOption, sortBoxOrderOption: bloc.options.notesSortBoxOrderOption, - input: category != null - ? notes.data?.where((final note) => note.favorite && note.category == category).toList() - : notes.data?.where((final note) => note.favorite).toList(), - builder: (final context, final sortedFavorites) => SortBoxBuilder( - sortBox: notesSortBox, - sortPropertyOption: bloc.options.notesSortPropertyOption, - sortBoxOrderOption: bloc.options.notesSortBoxOrderOption, - input: category != null - ? notes.data?.where((final note) => !note.favorite && note.category == category).toList() - : notes.data?.where((final note) => !note.favorite).toList(), - builder: (final context, final sortedNonFavorites) => NeonListView( - scrollKey: 'notes-notes', - withFloatingActionButton: true, - items: [ - ...sortedFavorites, - ...sortedNonFavorites, - ], - isLoading: notes.isLoading, - error: notes.error, - onRefresh: bloc.refresh, - builder: _buildNote, - ), + input: category != null ? notes.data?.where((final note) => note.category == category).toList() : notes.data, + builder: (final context, final sorted) => NeonListView( + scrollKey: 'notes-notes', + withFloatingActionButton: true, + items: sorted, + isLoading: notes.isLoading, + error: notes.error, + onRefresh: bloc.refresh, + builder: _buildNote, ), ), );