From 93d27f0cc7bc46c7f4b660f11b1915a7052aeffd Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 8 Dec 2022 13:25:58 +0100 Subject: [PATCH 1/3] neon: Cleanup list view refreshing --- packages/neon/lib/src/apps/files/widgets/browser_view.dart | 7 +------ packages/neon/lib/src/apps/news/widgets/articles_view.dart | 4 ---- packages/neon/lib/src/apps/news/widgets/feeds_view.dart | 7 +------ packages/neon/lib/src/apps/news/widgets/folders_view.dart | 7 +------ .../neon/lib/src/apps/notes/widgets/categories_view.dart | 7 +------ packages/neon/lib/src/apps/notes/widgets/notes_view.dart | 7 +------ packages/neon/lib/src/apps/notifications/pages/main.dart | 7 +------ packages/neon/lib/src/widgets/custom_listview.dart | 4 +--- 8 files changed, 7 insertions(+), 43 deletions(-) diff --git a/packages/neon/lib/src/apps/files/widgets/browser_view.dart b/packages/neon/lib/src/apps/files/widgets/browser_view.dart index 10a307ea..5fa2382e 100644 --- a/packages/neon/lib/src/apps/files/widgets/browser_view.dart +++ b/packages/neon/lib/src/apps/files/widgets/browser_view.dart @@ -141,12 +141,7 @@ class _FilesBrowserViewState extends State { ], isLoading: files.loading, error: files.error, - onRetry: () async { - await widget.bloc.refresh(); - }, - onRefresh: () async { - await widget.bloc.refresh(); - }, + onRefresh: widget.bloc.refresh, builder: (final context, final widget) => widget, topScrollingChildren: [ Align( diff --git a/packages/neon/lib/src/apps/news/widgets/articles_view.dart b/packages/neon/lib/src/apps/news/widgets/articles_view.dart index 3c06a172..13fd7af8 100644 --- a/packages/neon/lib/src/apps/news/widgets/articles_view.dart +++ b/packages/neon/lib/src/apps/news/widgets/articles_view.dart @@ -41,10 +41,6 @@ class _NewsArticlesViewState extends State { items: feeds.data == null ? null : sorted, isLoading: articles.loading || feeds.loading, error: articles.error ?? feeds.error, - onRetry: () async { - await widget.bloc.refresh(); - await widget.newsBloc.refresh(); - }, onRefresh: () async { await widget.bloc.refresh(); await widget.newsBloc.refresh(); diff --git a/packages/neon/lib/src/apps/news/widgets/feeds_view.dart b/packages/neon/lib/src/apps/news/widgets/feeds_view.dart index 85fcba06..836bb729 100644 --- a/packages/neon/lib/src/apps/news/widgets/feeds_view.dart +++ b/packages/neon/lib/src/apps/news/widgets/feeds_view.dart @@ -45,12 +45,7 @@ class NewsFeedsView extends StatelessWidget { items: sorted, isLoading: feeds.loading || folders.loading, error: feeds.error ?? folders.error, - onRetry: () async { - await bloc.refresh(); - }, - onRefresh: () async { - await bloc.refresh(); - }, + onRefresh: bloc.refresh, builder: (final context, final feed) => _buildFeed( context, feed, diff --git a/packages/neon/lib/src/apps/news/widgets/folders_view.dart b/packages/neon/lib/src/apps/news/widgets/folders_view.dart index 09b370e9..8270232c 100644 --- a/packages/neon/lib/src/apps/news/widgets/folders_view.dart +++ b/packages/neon/lib/src/apps/news/widgets/folders_view.dart @@ -47,12 +47,7 @@ class NewsFoldersView extends StatelessWidget { items: sorted, isLoading: feeds.loading || folders.loading, error: feeds.error ?? folders.error, - onRetry: () async { - await bloc.refresh(); - }, - onRefresh: () async { - await bloc.refresh(); - }, + onRefresh: bloc.refresh, builder: _buildFolder, ), ), diff --git a/packages/neon/lib/src/apps/notes/widgets/categories_view.dart b/packages/neon/lib/src/apps/notes/widgets/categories_view.dart index b7dab917..13f5a658 100644 --- a/packages/neon/lib/src/apps/notes/widgets/categories_view.dart +++ b/packages/neon/lib/src/apps/notes/widgets/categories_view.dart @@ -30,12 +30,7 @@ class NotesCategoriesView extends StatelessWidget { items: sorted, isLoading: notes.loading, error: notes.error, - onRetry: () async { - await bloc.refresh(); - }, - onRefresh: () async { - await bloc.refresh(); - }, + onRefresh: bloc.refresh, builder: _buildCategory, ), ), diff --git a/packages/neon/lib/src/apps/notes/widgets/notes_view.dart b/packages/neon/lib/src/apps/notes/widgets/notes_view.dart index 67f73ce8..394fafd2 100644 --- a/packages/neon/lib/src/apps/notes/widgets/notes_view.dart +++ b/packages/neon/lib/src/apps/notes/widgets/notes_view.dart @@ -60,12 +60,7 @@ class NotesView extends StatelessWidget { ], isLoading: notes.loading, error: notes.error, - onRetry: () async { - await bloc.refresh(); - }, - onRefresh: () async { - await bloc.refresh(); - }, + onRefresh: bloc.refresh, builder: _buildNote, ), ), diff --git a/packages/neon/lib/src/apps/notifications/pages/main.dart b/packages/neon/lib/src/apps/notifications/pages/main.dart index 39c822cd..1ca33b95 100644 --- a/packages/neon/lib/src/apps/notifications/pages/main.dart +++ b/packages/neon/lib/src/apps/notifications/pages/main.dart @@ -39,12 +39,7 @@ class _NotificationsMainPageState extends State { items: notifications.data, isLoading: notifications.loading, error: notifications.error, - onRetry: () async { - await widget.bloc.refresh(); - }, - onRefresh: () async { - await widget.bloc.refresh(); - }, + onRefresh: widget.bloc.refresh, builder: _buildNotification, ), ), diff --git a/packages/neon/lib/src/widgets/custom_listview.dart b/packages/neon/lib/src/widgets/custom_listview.dart index 5b591f39..09df63eb 100644 --- a/packages/neon/lib/src/widgets/custom_listview.dart +++ b/packages/neon/lib/src/widgets/custom_listview.dart @@ -5,7 +5,6 @@ class CustomListView extends StatelessWidget { required this.items, required this.isLoading, required this.error, - required this.onRetry, required this.onRefresh, required this.builder, this.scrollKey, @@ -18,7 +17,6 @@ class CustomListView extends StatelessWidget { final List? items; final bool isLoading; final dynamic error; - final Function() onRetry; final Future Function() onRefresh; final Widget Function(BuildContext, T data) builder; final String? scrollKey; @@ -52,7 +50,7 @@ class CustomListView extends StatelessWidget { ], ExceptionWidget( error, - onRetry: onRetry, + onRetry: onRefresh, ), if (items != null) ...[ for (final item in items!) ...[ From a67d2e871d31316cea239d31157e5e90f50be84e Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 8 Dec 2022 13:29:53 +0100 Subject: [PATCH 2/3] neon: Cleanup retries --- .../neon/lib/src/apps/news/dialogs/add_feed.dart | 4 +--- .../lib/src/apps/notes/dialogs/create_note.dart | 4 +--- .../src/apps/notes/dialogs/select_category.dart | 4 +--- packages/neon/lib/src/pages/account_settings.dart | 4 +--- packages/neon/lib/src/pages/home.dart | 12 +++--------- packages/neon/lib/src/pages/login.dart | 14 ++++---------- packages/neon/lib/src/widgets/account_tile.dart | 4 +--- 7 files changed, 12 insertions(+), 34 deletions(-) diff --git a/packages/neon/lib/src/apps/news/dialogs/add_feed.dart b/packages/neon/lib/src/apps/news/dialogs/add_feed.dart index 20af2835..b4833e7e 100644 --- a/packages/neon/lib/src/apps/news/dialogs/add_feed.dart +++ b/packages/neon/lib/src/apps/news/dialogs/add_feed.dart @@ -68,9 +68,7 @@ class _NewsAddFeedDialogState extends State { Center( child: ExceptionWidget( folders.error, - onRetry: () async { - await widget.bloc.refresh(); - }, + onRetry: widget.bloc.refresh, ), ), Center( diff --git a/packages/neon/lib/src/apps/notes/dialogs/create_note.dart b/packages/neon/lib/src/apps/notes/dialogs/create_note.dart index 401613c9..2682ff4e 100644 --- a/packages/neon/lib/src/apps/notes/dialogs/create_note.dart +++ b/packages/neon/lib/src/apps/notes/dialogs/create_note.dart @@ -51,9 +51,7 @@ class _NotesCreateNoteDialogState extends State { Center( child: ExceptionWidget( notes.error, - onRetry: () async { - await widget.bloc.refresh(); - }, + onRetry: widget.bloc.refresh, ), ), Center( diff --git a/packages/neon/lib/src/apps/notes/dialogs/select_category.dart b/packages/neon/lib/src/apps/notes/dialogs/select_category.dart index 1e4b1d66..6a21b7e6 100644 --- a/packages/neon/lib/src/apps/notes/dialogs/select_category.dart +++ b/packages/neon/lib/src/apps/notes/dialogs/select_category.dart @@ -39,9 +39,7 @@ class _NotesSelectCategoryDialogState extends State { Center( child: ExceptionWidget( notes.error, - onRetry: () async { - await widget.bloc.refresh(); - }, + onRetry: widget.bloc.refresh, ), ), Center( diff --git a/packages/neon/lib/src/pages/account_settings.dart b/packages/neon/lib/src/pages/account_settings.dart index aea3b48f..076f49ce 100644 --- a/packages/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/lib/src/pages/account_settings.dart @@ -74,9 +74,7 @@ class AccountSettingsPage extends StatelessWidget { ], ExceptionWidget( userDetails.error, - onRetry: () async { - await _userDetailsBloc.refresh(); - }, + onRetry: _userDetailsBloc.refresh, ), CustomLinearProgressIndicator( visible: userDetails.loading, diff --git a/packages/neon/lib/src/pages/home.dart b/packages/neon/lib/src/pages/home.dart index 162e04ac..612edea8 100644 --- a/packages/neon/lib/src/pages/home.dart +++ b/packages/neon/lib/src/pages/home.dart @@ -254,9 +254,7 @@ class _HomePageState extends State { ] else ...[ ExceptionWidget( capabilities.error, - onRetry: () async { - await _capabilitiesBloc.refresh(); - }, + onRetry: _capabilitiesBloc.refresh, ), CustomLinearProgressIndicator( visible: capabilities.loading, @@ -303,9 +301,7 @@ class _HomePageState extends State { ExceptionWidget( appImplementations.error, onlyIcon: isQuickBar, - onRetry: () async { - await _appsBloc.refresh(); - }, + onRetry: _appsBloc.refresh, ), CustomLinearProgressIndicator( visible: appImplementations.loading, @@ -539,9 +535,7 @@ class _HomePageState extends State { children: [ ExceptionWidget( appImplementations.error, - onRetry: () async { - await _appsBloc.refresh(); - }, + onRetry: _appsBloc.refresh, ), if (appImplementations.data != null) ...[ if (appImplementations.data!.isEmpty) ...[ diff --git a/packages/neon/lib/src/pages/login.dart b/packages/neon/lib/src/pages/login.dart index 142e0d36..04e491da 100644 --- a/packages/neon/lib/src/pages/login.dart +++ b/packages/neon/lib/src/pages/login.dart @@ -66,7 +66,7 @@ class _LoginPageState extends State { for (final a in accountsBloc.accounts.value) { if (a.id == account.id) { ExceptionWidget.showSnackbar(context, AppLocalizations.of(context).errorAccountAlreadyExists); - _loginBloc.setServerURL(result.server); + await _loginBloc.refresh(); return; } } @@ -168,9 +168,7 @@ class _LoginPageState extends State { height: 10, ), ElevatedButton( - onPressed: () { - _loginBloc.setServerURL(serverURLSnapshot.data!); - }, + onPressed: _loginBloc.refresh, child: Text(AppLocalizations.of(context).loginOpenAgain), ), ], @@ -224,17 +222,13 @@ class _LoginPageState extends State { if (serverConnectionStateSnapshot.data == ServerConnectionState.unreachable) ...[ ExceptionWidget( AppLocalizations.of(context).errorUnableToReachServer, - onRetry: () { - _loginBloc.setServerURL(serverURLSnapshot.data); - }, + onRetry: _loginBloc.refresh, ), ], if (serverConnectionStateSnapshot.data == ServerConnectionState.maintenanceMode) ...[ ExceptionWidget( AppLocalizations.of(context).errorServerInMaintenanceMode, - onRetry: () { - _loginBloc.setServerURL(serverURLSnapshot.data); - }, + onRetry: _loginBloc.refresh, ), ], ], diff --git a/packages/neon/lib/src/widgets/account_tile.dart b/packages/neon/lib/src/widgets/account_tile.dart index 6058cb75..45a6623e 100644 --- a/packages/neon/lib/src/widgets/account_tile.dart +++ b/packages/neon/lib/src/widgets/account_tile.dart @@ -71,9 +71,7 @@ class AccountTile extends StatelessWidget { userDetails.error!, onlyIcon: true, iconSize: 24, - onRetry: () async { - await userDetailsBloc.refresh(); - }, + onRetry: userDetailsBloc.refresh, ), ], ], From 00d002e60ab095d1ae44562287c20454f6d21cbc Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 8 Dec 2022 13:33:00 +0100 Subject: [PATCH 3/3] neon: Fix parallel awaits --- .../neon/lib/src/apps/news/blocs/news.dart | 44 ++++++++++--------- .../src/apps/news/widgets/articles_view.dart | 6 ++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/neon/lib/src/apps/news/blocs/news.dart b/packages/neon/lib/src/apps/news/blocs/news.dart index bb4882fd..f396b116 100644 --- a/packages/neon/lib/src/apps/news/blocs/news.dart +++ b/packages/neon/lib/src/apps/news/blocs/news.dart @@ -95,27 +95,29 @@ class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates @override Future refresh() async { - await requestManager.wrapNextcloud, NewsListFolders>( - client.id, - 'news-folders', - folders, - () async => client.news.listFolders(), - (final response) => response.folders, - ); - await requestManager.wrapNextcloud, NewsListFeeds>( - client.id, - 'news-feeds', - feeds, - () async => client.news.listFeeds(), - (final response) { - // This is a bit ugly, but IDGAF right now - if (response.newestItemId != null) { - _newestItemId = response.newestItemId!; - } - return response.feeds; - }, - ); - await mainArticlesBloc.reload(); + await Future.wait([ + requestManager.wrapNextcloud, NewsListFolders>( + client.id, + 'news-folders', + folders, + () async => client.news.listFolders(), + (final response) => response.folders, + ), + requestManager.wrapNextcloud, NewsListFeeds>( + client.id, + 'news-feeds', + feeds, + () async => client.news.listFeeds(), + (final response) { + // This is a bit ugly, but IDGAF right now + if (response.newestItemId != null) { + _newestItemId = response.newestItemId!; + } + return response.feeds; + }, + ), + mainArticlesBloc.reload(), + ]); } @override diff --git a/packages/neon/lib/src/apps/news/widgets/articles_view.dart b/packages/neon/lib/src/apps/news/widgets/articles_view.dart index 13fd7af8..9b77578b 100644 --- a/packages/neon/lib/src/apps/news/widgets/articles_view.dart +++ b/packages/neon/lib/src/apps/news/widgets/articles_view.dart @@ -42,8 +42,10 @@ class _NewsArticlesViewState extends State { isLoading: articles.loading || feeds.loading, error: articles.error ?? feeds.error, onRefresh: () async { - await widget.bloc.refresh(); - await widget.newsBloc.refresh(); + await Future.wait([ + widget.bloc.refresh(), + widget.newsBloc.refresh(), + ]); }, builder: (final context, final article) => _buildArticle( context,