Browse Source

Merge pull request #879 from nextcloud/refactor/neon

Refactor/neon
pull/881/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
6cf0de944b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/neon/neon/lib/src/bloc/bloc.dart
  2. 20
      packages/neon/neon/lib/src/sort_box/sort_box_builder.dart
  3. 1
      packages/neon/neon/lib/src/sort_box/sort_box_order_option_values.dart
  4. 9
      packages/neon/neon/lib/src/utils/app_route.dart
  5. 4
      packages/neon/neon_files/lib/routes.dart
  6. 4
      packages/neon/neon_files/lib/widgets/browser_view.dart
  7. 2
      packages/neon/neon_news/lib/blocs/article.dart
  8. 4
      packages/neon/neon_news/lib/routes.dart
  9. 4
      packages/neon/neon_news/lib/widgets/articles_view.dart
  10. 4
      packages/neon/neon_news/lib/widgets/feeds_view.dart
  11. 4
      packages/neon/neon_news/lib/widgets/folders_view.dart
  12. 2
      packages/neon/neon_notes/lib/blocs/note.dart
  13. 4
      packages/neon/neon_notes/lib/routes.dart
  14. 4
      packages/neon/neon_notes/lib/widgets/categories_view.dart
  15. 4
      packages/neon/neon_notes/lib/widgets/notes_view.dart
  16. 4
      packages/neon/neon_notifications/lib/routes.dart

2
packages/neon/neon/lib/src/bloc/bloc.dart

@ -19,7 +19,7 @@ abstract class InteractiveBloc extends Bloc {
final _errorsStreamController = StreamController<Object>();
late Stream<Object> errors = _errorsStreamController.stream.asBroadcastStream();
Future<void> refresh();
FutureOr<void> refresh();
void addError(final Object error) {
_errorsStreamController.add(error);

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,

9
packages/neon/neon/lib/src/utils/app_route.dart

@ -4,9 +4,11 @@ import 'package:go_router/go_router.dart';
/// [RouteData] for the initial page of an app.
///
/// Subclasses must override one of [build] or [redirect].
/// Routes should be prefixed with [appsBaseRoutePrefix].
@immutable
abstract class NeonAppRoute extends GoRouteData {
const NeonAppRoute();
abstract class NeonBaseAppRoute extends GoRouteData {
/// Creates a new app base route.
const NeonBaseAppRoute();
@override
Page<void> buildPage(final BuildContext context, final GoRouterState state) => NoTransitionPage(
@ -14,4 +16,5 @@ abstract class NeonAppRoute extends GoRouteData {
);
}
const appsRoutePrefix = '/apps/';
/// Prefix for [NeonBaseAppRoute]s.
const appsBaseRoutePrefix = '/apps/';

4
packages/neon/neon_files/lib/routes.dart

@ -7,11 +7,11 @@ import 'package:neon_files/neon_files.dart';
part 'routes.g.dart';
@TypedGoRoute<FilesAppRoute>(
path: '$appsRoutePrefix${AppIDs.files}',
path: '$appsBaseRoutePrefix${AppIDs.files}',
name: AppIDs.files,
)
@immutable
class FilesAppRoute extends NeonAppRoute {
class FilesAppRoute extends NeonBaseAppRoute {
const FilesAppRoute();
@override

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),
},

2
packages/neon/neon_news/lib/blocs/article.dart

@ -44,7 +44,7 @@ class NewsArticleBloc extends InteractiveBloc implements NewsArticleBlocEvents,
BehaviorSubject<bool> unread = BehaviorSubject<bool>();
@override
Future<void> refresh() async {}
void refresh() {}
@override
void markArticleAsRead() {

4
packages/neon/neon_news/lib/routes.dart

@ -7,11 +7,11 @@ import 'package:neon_news/neon_news.dart';
part 'routes.g.dart';
@TypedGoRoute<NewsAppRoute>(
path: '$appsRoutePrefix${AppIDs.news}',
path: '$appsBaseRoutePrefix${AppIDs.news}',
name: AppIDs.news,
)
@immutable
class NewsAppRoute extends NeonAppRoute {
class NewsAppRoute extends NeonBaseAppRoute {
const NewsAppRoute();
@override

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);

2
packages/neon/neon_notes/lib/blocs/note.dart

@ -62,7 +62,7 @@ class NotesNoteBloc extends InteractiveBloc implements NotesNoteBlocEvents, Note
BehaviorSubject<String> category = BehaviorSubject<String>();
@override
Future<void> refresh() async {}
void refresh() {}
@override
void updateCategory(final String category) {

4
packages/neon/neon_notes/lib/routes.dart

@ -7,11 +7,11 @@ import 'package:neon_notes/neon_notes.dart';
part 'routes.g.dart';
@TypedGoRoute<NotesAppRoute>(
path: '$appsRoutePrefix${AppIDs.notes}',
path: '$appsBaseRoutePrefix${AppIDs.notes}',
name: AppIDs.notes,
)
@immutable
class NotesAppRoute extends NeonAppRoute {
class NotesAppRoute extends NeonBaseAppRoute {
const NotesAppRoute();
@override

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',

4
packages/neon/neon_notifications/lib/routes.dart

@ -7,11 +7,11 @@ import 'package:neon_notifications/neon_notifications.dart';
part 'routes.g.dart';
@TypedGoRoute<NotificationsAppRoute>(
path: '$appsRoutePrefix${AppIDs.notifications}',
path: '$appsBaseRoutePrefix${AppIDs.notifications}',
name: AppIDs.notifications,
)
@immutable
class NotificationsAppRoute extends NeonAppRoute {
class NotificationsAppRoute extends NeonBaseAppRoute {
const NotificationsAppRoute();
@override

Loading…
Cancel
Save