Browse Source

refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): reword SortBoxBuilder api

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/879/head
Nikolas Rimikis 1 year ago
parent
commit
770d9db6cd
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 20
      packages/neon/neon/lib/src/sort_box/sort_box_builder.dart
  2. 1
      packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart
  3. 4
      packages/neon/neon_files/lib/widgets/browser_view.dart
  4. 4
      packages/neon/neon_news/lib/widgets/articles_view.dart
  5. 4
      packages/neon/neon_news/lib/widgets/feeds_view.dart
  6. 4
      packages/neon/neon_news/lib/widgets/folders_view.dart
  7. 4
      packages/neon/neon_notes/lib/widgets/categories_view.dart
  8. 4
      packages/neon/neon_notes/lib/widgets/notes_view.dart

20
packages/neon/neon/lib/src/sort_box/sort_box_builder.dart

@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:neon/src/settings/models/option.dart';
import 'package:sort_box/sort_box.dart';
/// Signature for a function that creates a widget for a given sorted list.
@ -11,19 +11,25 @@ typedef SortBoxWidgetBuilder<T> = Widget Function(BuildContext context, List<T>
///
/// Used together with a [SortBox] to sort a given list.
class SortBoxBuilder<T extends Enum, R> extends StatelessWidget {
/// Creates a new sort box builder.
SortBoxBuilder({
required this.sortBox,
required this.sortPropertyOption,
required this.sortBoxOrderOption,
required this.sortProperty,
required this.sortBoxOrder,
required final List<R>? input,
required this.builder,
this.presort,
super.key,
}) : input = input ?? [];
/// The box containing all sorting properties.
final SortBox<T, R> sortBox;
final SelectOption<T> sortPropertyOption;
final SelectOption<SortBoxOrder> sortBoxOrderOption;
/// The property to sort on.
final ValueListenable<T> sortProperty;
/// The sorting order applied to the [sortProperty].
final ValueListenable<SortBoxOrder> sortBoxOrder;
/// Input list to sort.
final List<R> input;
@ -42,9 +48,9 @@ class SortBoxBuilder<T extends Enum, R> extends StatelessWidget {
}
return ValueListenableBuilder<T>(
valueListenable: sortPropertyOption,
valueListenable: sortProperty,
builder: (final context, final property, final _) => ValueListenableBuilder<SortBoxOrder>(
valueListenable: sortBoxOrderOption,
valueListenable: sortBoxOrder,
builder: (final context, final order, final _) {
final box = (property, order);

1
packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart

@ -2,6 +2,7 @@ import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/models/label_builder.dart';
import 'package:sort_box/sort_box.dart';
/// Sort box order labels used in an `SelectOption`.
final sortBoxOrderOptionValues = <SortBoxOrder, LabelBuilder>{
SortBoxOrder.ascending: (final context) => AppLocalizations.of(context).optionsSortOrderAscending,
SortBoxOrder.descending: (final context) => AppLocalizations.of(context).optionsSortOrderDescending,

4
packages/neon/neon_files/lib/widgets/browser_view.dart

@ -60,8 +60,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
},
child: SortBoxBuilder<FilesSortProperty, WebDavFile>(
sortBox: filesSortBox,
sortPropertyOption: widget.bloc.options.filesSortPropertyOption,
sortBoxOrderOption: widget.bloc.options.filesSortBoxOrderOption,
sortProperty: widget.bloc.options.filesSortPropertyOption,
sortBoxOrder: widget.bloc.options.filesSortBoxOrderOption,
presort: const {
(FilesSortProperty.isFolder, SortBoxOrder.ascending),
},

4
packages/neon/neon_news/lib/widgets/articles_view.dart

@ -31,8 +31,8 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
stream: widget.bloc.articles,
builder: (final context, final articles) => SortBoxBuilder<ArticlesSortProperty, NewsArticle>(
sortBox: articlesSortBox,
sortPropertyOption: widget.newsBloc.options.articlesSortPropertyOption,
sortBoxOrderOption: widget.newsBloc.options.articlesSortBoxOrderOption,
sortProperty: widget.newsBloc.options.articlesSortPropertyOption,
sortBoxOrder: widget.newsBloc.options.articlesSortBoxOrderOption,
input: articles.data,
builder: (final context, final sorted) => NeonListView(
scrollKey: 'news-articles',

4
packages/neon/neon_news/lib/widgets/feeds_view.dart

@ -17,8 +17,8 @@ class NewsFeedsView extends StatelessWidget {
stream: bloc.feeds,
builder: (final context, final feeds) => SortBoxBuilder<FeedsSortProperty, NewsFeed>(
sortBox: feedsSortBox,
sortPropertyOption: bloc.options.feedsSortPropertyOption,
sortBoxOrderOption: bloc.options.feedsSortBoxOrderOption,
sortProperty: bloc.options.feedsSortPropertyOption,
sortBoxOrder: bloc.options.feedsSortBoxOrderOption,
input: folders.hasData
? feeds.data?.where((final f) => folderID == null || f.folderId == folderID).toList()
: null,

4
packages/neon/neon_news/lib/widgets/folders_view.dart

@ -15,8 +15,8 @@ class NewsFoldersView extends StatelessWidget {
stream: bloc.feeds,
builder: (final context, final feeds) => SortBoxBuilder<FoldersSortProperty, FolderFeedsWrapper>(
sortBox: foldersSortBox,
sortPropertyOption: bloc.options.foldersSortPropertyOption,
sortBoxOrderOption: bloc.options.foldersSortBoxOrderOption,
sortProperty: bloc.options.foldersSortPropertyOption,
sortBoxOrder: bloc.options.foldersSortBoxOrderOption,
input: feeds.hasData
? folders.data?.map((final folder) {
final feedsInFolder = feeds.requireData.where((final feed) => feed.folderId == folder.id);

4
packages/neon/neon_notes/lib/widgets/categories_view.dart

@ -13,8 +13,8 @@ class NotesCategoriesView extends StatelessWidget {
stream: bloc.notes,
builder: (final context, final notes) => SortBoxBuilder<CategoriesSortProperty, NoteCategory>(
sortBox: categoriesSortBox,
sortPropertyOption: bloc.options.categoriesSortPropertyOption,
sortBoxOrderOption: bloc.options.categoriesSortBoxOrderOption,
sortProperty: bloc.options.categoriesSortPropertyOption,
sortBoxOrder: bloc.options.categoriesSortBoxOrderOption,
input: notes.data
?.map((final note) => note.category)
.toSet()

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

@ -18,8 +18,8 @@ class NotesView extends StatelessWidget {
presort: const {
(NotesSortProperty.favorite, SortBoxOrder.ascending),
},
sortPropertyOption: bloc.options.notesSortPropertyOption,
sortBoxOrderOption: bloc.options.notesSortBoxOrderOption,
sortProperty: bloc.options.notesSortPropertyOption,
sortBoxOrder: bloc.options.notesSortBoxOrderOption,
input: category != null ? notes.data?.where((final note) => note.category == category).toList() : notes.data,
builder: (final context, final sorted) => NeonListView(
scrollKey: 'notes-notes',

Loading…
Cancel
Save