From 33619caf87a5ba8574e3cd0f1dd8395327d2cd57 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Fri, 26 May 2023 21:05:32 +0200 Subject: [PATCH 1/3] neon: fix login/logout routing --- packages/neon/neon/lib/src/pages/account_settings.dart | 2 ++ packages/neon/neon/lib/src/pages/login.dart | 2 ++ packages/neon/neon/lib/src/router.dart | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/neon/neon/lib/src/pages/account_settings.dart b/packages/neon/neon/lib/src/pages/account_settings.dart index 11813dbb..29a1057d 100644 --- a/packages/neon/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/neon/lib/src/pages/account_settings.dart @@ -29,6 +29,8 @@ class AccountSettingsPage extends StatelessWidget { AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), )) { bloc.removeAccount(account); + // ignore: use_build_context_synchronously + const HomeRoute().go(context); } }, tooltip: AppLocalizations.of(context).accountOptionsRemove, diff --git a/packages/neon/neon/lib/src/pages/login.dart b/packages/neon/neon/lib/src/pages/login.dart index b3ed5c2d..a7715cbf 100644 --- a/packages/neon/neon/lib/src/pages/login.dart +++ b/packages/neon/neon/lib/src/pages/login.dart @@ -84,6 +84,8 @@ class _LoginPageState extends State { ..addAccount(account) ..setActiveAccount(account); } + // ignore: use_build_context_synchronously + const HomeRoute().go(context); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index d6c397c5..8491fde9 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -21,10 +21,6 @@ class AppRouter extends GoRouter { return const LoginRoute().location; } - if (state.location == const LoginRoute().location) { - return const HomeRoute().location; - } - return null; }, routes: $appRoutes, From 22f94a5c309d1c74527f624f312b572cf95d1f6d Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sun, 28 May 2023 12:12:19 +0200 Subject: [PATCH 2/3] neon: use helper methods to find active application --- packages/neon/neon/lib/src/router.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index 8491fde9..4e9de5eb 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -105,7 +105,7 @@ class NextcloudAppSettingsRoute extends GoRouteData { @override Widget build(final BuildContext context, final GoRouterState state) { final appImplementations = Provider.of>(context, listen: false); - final appImplementation = appImplementations.firstWhere((final app) => app.id == appid); + final appImplementation = appImplementations.find(appid)!; return NextcloudAppSettingsPage(appImplementation: appImplementation); } From 367f2070449709608d062324e0e6fa1022e1fac2 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sun, 28 May 2023 12:13:09 +0200 Subject: [PATCH 3/3] neon: add `AddAccount` route to prevent trying to pop the last page --- .../neon/lib/src/pages/account_settings.dart | 12 ++++++++-- .../neon/neon/lib/src/pages/settings.dart | 2 +- packages/neon/neon/lib/src/router.dart | 19 +++++++++++++-- packages/neon/neon/lib/src/router.g.dart | 23 +++++++++++++++++-- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/neon/neon/lib/src/pages/account_settings.dart b/packages/neon/neon/lib/src/pages/account_settings.dart index 29a1057d..0b95a9f6 100644 --- a/packages/neon/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/neon/lib/src/pages/account_settings.dart @@ -28,9 +28,17 @@ class AccountSettingsPage extends StatelessWidget { // ignore: use_build_context_synchronously AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), )) { + final isActive = bloc.activeAccount.value == account; + bloc.removeAccount(account); - // ignore: use_build_context_synchronously - const HomeRoute().go(context); + + if (isActive) { + // ignore: use_build_context_synchronously + const HomeRoute().go(context); + } else { + // ignore: use_build_context_synchronously + Navigator.of(context).pop(); + } } }, tooltip: AppLocalizations.of(context).accountOptionsRemove, diff --git a/packages/neon/neon/lib/src/pages/settings.dart b/packages/neon/neon/lib/src/pages/settings.dart index e51b1c33..145d740b 100644 --- a/packages/neon/neon/lib/src/pages/settings.dart +++ b/packages/neon/neon/lib/src/pages/settings.dart @@ -183,7 +183,7 @@ class _SettingsPageState extends State { CustomSettingsTile( title: ElevatedButton.icon( onPressed: () { - const LoginRoute().go(context); + const AddAccountRoute().go(context); }, icon: const Icon(MdiIcons.accountPlus), label: Text(AppLocalizations.of(context).globalOptionsAccountsAdd), diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index 4e9de5eb..a3ca0b3d 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -1,5 +1,6 @@ // ignore: prefer_mixin -import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; import 'package:neon/neon.dart'; import 'package:provider/provider.dart'; @@ -11,12 +12,14 @@ class AppRouter extends GoRouter { required final GlobalKey navigatorKey, required final AccountsBloc accountsBloc, }) : super( + debugLogDiagnostics: kDebugMode, refreshListenable: StreamListenable.behaviorSubject(accountsBloc.activeAccount), navigatorKey: navigatorKey, initialLocation: const HomeRoute().location, redirect: (final context, final state) { final account = accountsBloc.activeAccount.valueOrNull; + // redirect to loginscreen when no account is logged in if (account == null) { return const LoginRoute().location; } @@ -56,9 +59,13 @@ class AccountSettingsRoute extends GoRouteData { name: 'Settings', routes: [ TypedGoRoute( - path: ':appid', + path: 'apps/:appid', name: 'NextcloudAppSettings', ), + TypedGoRoute( + path: 'account/add', + name: 'addAccount', + ), TypedGoRoute( path: 'account/:accountid', name: 'AccountSettings', @@ -94,6 +101,14 @@ class LoginRoute extends GoRouteData { Widget build(final BuildContext context, final GoRouterState state) => LoginPage(serverURL: server); } +@immutable +class AddAccountRoute extends GoRouteData { + const AddAccountRoute(); + + @override + Widget build(final BuildContext context, final GoRouterState state) => const LoginPage(); +} + @immutable class NextcloudAppSettingsRoute extends GoRouteData { const NextcloudAppSettingsRoute({ diff --git a/packages/neon/neon/lib/src/router.g.dart b/packages/neon/neon/lib/src/router.g.dart index 406213ea..8a9d98dc 100644 --- a/packages/neon/neon/lib/src/router.g.dart +++ b/packages/neon/neon/lib/src/router.g.dart @@ -22,10 +22,15 @@ RouteBase get $homeRoute => GoRouteData.$route( factory: $SettingsRouteExtension._fromState, routes: [ GoRouteData.$route( - path: ':appid', + path: 'apps/:appid', name: 'NextcloudAppSettings', factory: $NextcloudAppSettingsRouteExtension._fromState, ), + GoRouteData.$route( + path: 'account/add', + name: 'addAccount', + factory: $AddAccountRouteExtension._fromState, + ), GoRouteData.$route( path: 'account/:accountid', name: 'AccountSettings', @@ -70,7 +75,21 @@ extension $NextcloudAppSettingsRouteExtension on NextcloudAppSettingsRoute { ); String get location => GoRouteData.$location( - '/settings/${Uri.encodeComponent(appid)}', + '/settings/apps/${Uri.encodeComponent(appid)}', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => context.pushReplacement(location); +} + +extension $AddAccountRouteExtension on AddAccountRoute { + static AddAccountRoute _fromState(GoRouterState state) => const AddAccountRoute(); + + String get location => GoRouteData.$location( + '/settings/account/add', ); void go(BuildContext context) => context.go(location);