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. 34
      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 { enum NotesSortProperty {
lastModified, lastModified,
alphabetical, alphabetical,
favorite,
} }
enum CategoriesSortProperty { 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.alphabetical: (final note) => note.title.toLowerCase(),
NotesSortProperty.lastModified: (final note) => note.modified, NotesSortProperty.lastModified: (final note) => note.modified,
NotesSortProperty.favorite: (final note) => note.favorite ? 0 : 1,
}, },
{ {
NotesSortProperty.alphabetical: { NotesSortProperty.alphabetical: {
(NotesSortProperty.lastModified, SortBoxOrder.descending), (NotesSortProperty.lastModified, SortBoxOrder.descending),
}, },
NotesSortProperty.lastModified: {
(NotesSortProperty.alphabetical, SortBoxOrder.ascending),
},
}, },
); );

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

@ -15,30 +15,20 @@ class NotesView extends StatelessWidget {
stream: bloc.notes, stream: bloc.notes,
builder: (final context, final notes) => SortBoxBuilder<NotesSortProperty, NotesNote>( builder: (final context, final notes) => SortBoxBuilder<NotesSortProperty, NotesNote>(
sortBox: notesSortBox, sortBox: notesSortBox,
presort: const {
(NotesSortProperty.favorite, SortBoxOrder.ascending),
},
sortPropertyOption: bloc.options.notesSortPropertyOption, sortPropertyOption: bloc.options.notesSortPropertyOption,
sortBoxOrderOption: bloc.options.notesSortBoxOrderOption, sortBoxOrderOption: bloc.options.notesSortBoxOrderOption,
input: category != null input: category != null ? notes.data?.where((final note) => note.category == category).toList() : notes.data,
? notes.data?.where((final note) => note.favorite && note.category == category).toList() builder: (final context, final sorted) => NeonListView<NotesNote>(
: notes.data?.where((final note) => note.favorite).toList(), scrollKey: 'notes-notes',
builder: (final context, final sortedFavorites) => SortBoxBuilder<NotesSortProperty, NotesNote>( withFloatingActionButton: true,
sortBox: notesSortBox, items: sorted,
sortPropertyOption: bloc.options.notesSortPropertyOption, isLoading: notes.isLoading,
sortBoxOrderOption: bloc.options.notesSortBoxOrderOption, error: notes.error,
input: category != null onRefresh: bloc.refresh,
? notes.data?.where((final note) => !note.favorite && note.category == category).toList() builder: _buildNote,
: notes.data?.where((final note) => !note.favorite).toList(),
builder: (final context, final sortedNonFavorites) => NeonListView<NotesNote>(
scrollKey: 'notes-notes',
withFloatingActionButton: true,
items: [
...sortedFavorites,
...sortedNonFavorites,
],
isLoading: notes.isLoading,
error: notes.error,
onRefresh: bloc.refresh,
builder: _buildNote,
),
), ),
), ),
); );

Loading…
Cancel
Save