Browse Source

refactor(neon_notes): use presorting in the NotesView

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/591/head
Nikolas Rimikis 1 year ago
parent
commit
a3419a838c
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 1
      packages/neon/neon_notes/lib/options.dart
  2. 4
      packages/neon/neon_notes/lib/sort/notes.dart
  3. 22
      packages/neon/neon_notes/lib/widgets/notes_view.dart

1
packages/neon/neon_notes/lib/options.dart

@ -108,6 +108,7 @@ enum DefaultNoteViewType {
enum NotesSortProperty {
lastModified,
alphabetical,
favorite,
}
enum CategoriesSortProperty {

4
packages/neon/neon_notes/lib/sort/notes.dart

@ -4,10 +4,14 @@ final notesSortBox = SortBox<NotesSortProperty, NotesNote>(
{
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),
},
},
);

22
packages/neon/neon_notes/lib/widgets/notes_view.dart

@ -15,32 +15,22 @@ class NotesView extends StatelessWidget {
stream: bloc.notes,
builder: (final context, final notes) => SortBoxBuilder<NotesSortProperty, NotesNote>(
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<NotesSortProperty, NotesNote>(
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<NotesNote>(
input: category != null ? notes.data?.where((final note) => note.category == category).toList() : notes.data,
builder: (final context, final sorted) => NeonListView<NotesNote>(
scrollKey: 'notes-notes',
withFloatingActionButton: true,
items: [
...sortedFavorites,
...sortedNonFavorites,
],
items: sorted,
isLoading: notes.isLoading,
error: notes.error,
onRefresh: bloc.refresh,
builder: _buildNote,
),
),
),
);
Widget _buildNote(

Loading…
Cancel
Save