From 770d9db6cd73493bd701bd46002e91f9071bcdda Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Fri, 29 Sep 2023 15:56:33 +0200 Subject: [PATCH] refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): reword SortBoxBuilder api Signed-off-by: Nikolas Rimikis --- .../lib/src/sort_box/sort_box_builder.dart | 20 ++++++++++++------- .../sort_box_order_option_values.dart | 1 + .../neon_files/lib/widgets/browser_view.dart | 4 ++-- .../neon_news/lib/widgets/articles_view.dart | 4 ++-- .../neon_news/lib/widgets/feeds_view.dart | 4 ++-- .../neon_news/lib/widgets/folders_view.dart | 4 ++-- .../lib/widgets/categories_view.dart | 4 ++-- .../neon_notes/lib/widgets/notes_view.dart | 4 ++-- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/neon/neon/lib/src/sort_box/sort_box_builder.dart b/packages/neon/neon/lib/src/sort_box/sort_box_builder.dart index 35803216..2a6e323f 100644 --- a/packages/neon/neon/lib/src/sort_box/sort_box_builder.dart +++ b/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 = Widget Function(BuildContext context, List /// /// Used together with a [SortBox] to sort a given list. class SortBoxBuilder 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? input, required this.builder, this.presort, super.key, }) : input = input ?? []; + /// The box containing all sorting properties. final SortBox sortBox; - final SelectOption sortPropertyOption; - final SelectOption sortBoxOrderOption; + + /// The property to sort on. + final ValueListenable sortProperty; + + /// The sorting order applied to the [sortProperty]. + final ValueListenable sortBoxOrder; /// Input list to sort. final List input; @@ -42,9 +48,9 @@ class SortBoxBuilder extends StatelessWidget { } return ValueListenableBuilder( - valueListenable: sortPropertyOption, + valueListenable: sortProperty, builder: (final context, final property, final _) => ValueListenableBuilder( - valueListenable: sortBoxOrderOption, + valueListenable: sortBoxOrder, builder: (final context, final order, final _) { final box = (property, order); diff --git a/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart b/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart index 2d69f581..a76b6ea2 100644 --- a/packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart +++ b/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.ascending: (final context) => AppLocalizations.of(context).optionsSortOrderAscending, SortBoxOrder.descending: (final context) => AppLocalizations.of(context).optionsSortOrderDescending, diff --git a/packages/neon/neon_files/lib/widgets/browser_view.dart b/packages/neon/neon_files/lib/widgets/browser_view.dart index 435cc41b..67cc8564 100644 --- a/packages/neon/neon_files/lib/widgets/browser_view.dart +++ b/packages/neon/neon_files/lib/widgets/browser_view.dart @@ -60,8 +60,8 @@ class _FilesBrowserViewState extends State { }, child: SortBoxBuilder( 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), }, diff --git a/packages/neon/neon_news/lib/widgets/articles_view.dart b/packages/neon/neon_news/lib/widgets/articles_view.dart index 0c98cc77..88cb8563 100644 --- a/packages/neon/neon_news/lib/widgets/articles_view.dart +++ b/packages/neon/neon_news/lib/widgets/articles_view.dart @@ -31,8 +31,8 @@ class _NewsArticlesViewState extends State { stream: widget.bloc.articles, builder: (final context, final articles) => SortBoxBuilder( 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', diff --git a/packages/neon/neon_news/lib/widgets/feeds_view.dart b/packages/neon/neon_news/lib/widgets/feeds_view.dart index ae4e9a43..10002f8f 100644 --- a/packages/neon/neon_news/lib/widgets/feeds_view.dart +++ b/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( 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, diff --git a/packages/neon/neon_news/lib/widgets/folders_view.dart b/packages/neon/neon_news/lib/widgets/folders_view.dart index fc3da967..2e7e45a0 100644 --- a/packages/neon/neon_news/lib/widgets/folders_view.dart +++ b/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( 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); diff --git a/packages/neon/neon_notes/lib/widgets/categories_view.dart b/packages/neon/neon_notes/lib/widgets/categories_view.dart index 794a2c4b..dd04001f 100644 --- a/packages/neon/neon_notes/lib/widgets/categories_view.dart +++ b/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( 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() diff --git a/packages/neon/neon_notes/lib/widgets/notes_view.dart b/packages/neon/neon_notes/lib/widgets/notes_view.dart index 07b8730c..e1fb7ac7 100644 --- a/packages/neon/neon_notes/lib/widgets/notes_view.dart +++ b/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',