Fix routing to home after initial account creation

This commit is contained in:
Brandon Vandegrift 2025-04-03 14:27:56 -04:00
parent f4407e5284
commit e1f081105a
3 changed files with 27 additions and 16 deletions

View File

@ -63,10 +63,13 @@ class _NewAccountPageState extends WindowSetupState<NewAccountPage> {
return false;
}
final isFirstAccount =
AccountRepository.instance.getLocalAccounts().isEmpty;
final writableSuperIdentity = await AccountRepository.instance
.createWithNewSuperIdentity(accountSpec);
GoRouterHelper(context).pushReplacement('/new_account/recovery_key',
extra: [writableSuperIdentity, accountSpec.name]);
extra: [writableSuperIdentity, accountSpec.name, isFirstAccount]);
return true;
} finally {
@ -92,11 +95,15 @@ class _NewAccountPageState extends WindowSetupState<NewAccountPage> {
return StyledScaffold(
appBar: DefaultAppBar(
title: Text(translate('new_account_page.titlebar')),
leading: Navigator.canPop(context)
leading: GoRouterHelper(context).canPop()
? IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
if (GoRouterHelper(context).canPop()) {
GoRouterHelper(context).pop();
} else {
GoRouterHelper(context).go('/');
}
},
)
: null,

View File

@ -25,15 +25,18 @@ class ShowRecoveryKeyPage extends StatefulWidget {
const ShowRecoveryKeyPage(
{required WritableSuperIdentity writableSuperIdentity,
required String name,
required bool isFirstAccount,
super.key})
: _writableSuperIdentity = writableSuperIdentity,
_name = name;
_name = name,
_isFirstAccount = isFirstAccount;
@override
State<ShowRecoveryKeyPage> createState() => _ShowRecoveryKeyPageState();
final WritableSuperIdentity _writableSuperIdentity;
final String _name;
final bool _isFirstAccount;
}
class _ShowRecoveryKeyPageState extends WindowSetupState<ShowRecoveryKeyPage> {
@ -248,9 +251,13 @@ class _ShowRecoveryKeyPageState extends WindowSetupState<ShowRecoveryKeyPage> {
child: ElevatedButton(
onPressed: () {
if (context.mounted) {
Navigator.canPop(context)
? GoRouterHelper(context).pop()
: GoRouterHelper(context).go('/');
if (widget._isFirstAccount) {
GoRouterHelper(context).go('/');
} else {
GoRouterHelper(context).canPop()
? GoRouterHelper(context).pop()
: GoRouterHelper(context).go('/');
}
}
},
child: Text(translate('button.finish')).paddingAll(8))

View File

@ -96,7 +96,8 @@ class RouterCubit extends Cubit<RouterState> {
if (extra == null ||
extra is! List<Object> ||
extra[0] is! WritableSuperIdentity ||
extra[1] is! String) {
extra[1] is! String ||
extra[2] is! bool) {
return '/';
}
return null;
@ -107,7 +108,8 @@ class RouterCubit extends Cubit<RouterState> {
return ShowRecoveryKeyPage(
writableSuperIdentity:
extra[0] as WritableSuperIdentity,
name: extra[1] as String);
name: extra[1] as String,
isFirstAccount: extra[2] as bool);
}),
]),
GoRoute(
@ -123,14 +125,8 @@ class RouterCubit extends Cubit<RouterState> {
/// Redirects when our state changes
String? redirect(BuildContext context, GoRouterState goRouterState) {
// No matter where we are, if there's not
switch (goRouterState.matchedLocation) {
case '/':
if (!state.hasAnyAccount) {
return '/new_account';
}
return null;
// We can go to any of these routes without an account.
case '/new_account':
return null;
case '/new_account/recovery_key':
@ -139,6 +135,7 @@ class RouterCubit extends Cubit<RouterState> {
return null;
case '/developer':
return null;
// Otherwise, if there's no account, we need to go to the new account page.
default:
return state.hasAnyAccount ? null : '/new_account';
}