Skip to content

Commit

Permalink
feat(router): enables a route for the get-started page PE-4742
Browse files Browse the repository at this point in the history
  • Loading branch information
matibat committed Oct 20, 2023
1 parent 9fcee29 commit 08a2d25
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
7 changes: 5 additions & 2 deletions lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
logger.e('Failed to unlock user with biometrics', e);
}
}

emit(const PromptPassword());

return;
}

emit(LoginInitial(_arConnectService.isExtensionPresent()));
if (event.gettinStarted) {
_handleCreateNewWalletEvent(const CreateNewWallet(), emit);
} else {
emit(LoginInitial(_arConnectService.isExtensionPresent()));
}
}

Future<void> _handleUnlockUserWithPasswordEvent(
Expand Down
6 changes: 5 additions & 1 deletion lib/authentication/login/blocs/login_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class AddWalletFromArConnect extends LoginEvent {
}

class CheckIfUserIsLoggedIn extends LoginEvent {
const CheckIfUserIsLoggedIn();
final bool gettinStarted;

const CheckIfUserIsLoggedIn({
this.gettinStarted = false,
});

@override
List<Object> get props => [];
Expand Down
23 changes: 17 additions & 6 deletions lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:responsive_builder/responsive_builder.dart';

class LoginPage extends StatefulWidget {
const LoginPage({super.key});
final bool gettingStarted;

const LoginPage({
super.key,
this.gettingStarted = false,
});

@override
State<LoginPage> createState() => _LoginPageState();
Expand All @@ -46,12 +51,18 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
final loginBloc = LoginBloc(
arConnectService: ArConnectService(),
arDriveAuth: context.read<ArDriveAuth>(),
userRepository: context.read<UserRepository>(),
)..add(
CheckIfUserIsLoggedIn(
gettinStarted: widget.gettingStarted,
),
);

return BlocProvider<LoginBloc>(
create: (context) => LoginBloc(
arConnectService: ArConnectService(),
arDriveAuth: context.read<ArDriveAuth>(),
userRepository: context.read<UserRepository>(),
)..add(const CheckIfUserIsLoggedIn()),
create: (context) => loginBloc,
child: BlocConsumer<LoginBloc, LoginState>(
listener: (context, state) {
if (state is LoginOnBoarding) {
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/app_route_information_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class AppRouteInformationParser extends RouteInformationParser<AppRoutePath> {
case 'sign-in':
// Handle '/sign-in'
return AppRoutePath.signIn();
case 'get-started':
return AppRoutePath.getStarted();
case 'drives':
if (uri.pathSegments.length > 1) {
final driveId = uri.pathSegments[1];
Expand Down Expand Up @@ -76,6 +78,8 @@ class AppRouteInformationParser extends RouteInformationParser<AppRoutePath> {
RouteInformation restoreRouteInformation(AppRoutePath configuration) {
if (configuration.signingIn) {
return const RouteInformation(location: '/sign-in');
} else if (configuration.getStarted) {
return const RouteInformation(location: '/get-started');
} else if (configuration.driveId != null) {
if (configuration.driveName != null &&
configuration.sharedRawDriveKey != null) {
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/app_route_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class AppRoutePath {
/// Whether or not the user is trying to sign in.
final bool signingIn;

final bool getStarted;

final String? driveId;
final String? driveName;
final String? driveFolderId;
Expand All @@ -23,6 +25,7 @@ class AppRoutePath {

const AppRoutePath({
this.signingIn = false,
this.getStarted = false,
this.driveId,
this.driveName,
this.driveFolderId,
Expand All @@ -36,6 +39,8 @@ class AppRoutePath {
/// Creates a route that lets the user sign in.
factory AppRoutePath.signIn() => const AppRoutePath(signingIn: true);

factory AppRoutePath.getStarted() => const AppRoutePath(getStarted: true);

/// Creates a route that points to a particular drive.
factory AppRoutePath.driveDetail({
required String driveId,
Expand Down
12 changes: 11 additions & 1 deletion lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
with ChangeNotifier, PopNavigatorRouterDelegateMixin<AppRoutePath> {
bool signingIn = false;

bool gettingStarted = false;

String? driveId;
String? driveName;
String? driveFolderId;
Expand All @@ -46,6 +48,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
@override
AppRoutePath get currentConfiguration => AppRoutePath(
signingIn: signingIn,
getStarted: gettingStarted,
driveId: driveId,
driveName: driveName,
sharedDriveKey: sharedDriveKey,
Expand Down Expand Up @@ -99,16 +102,19 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
anonymouslyShowDriveDetail || isViewingSharedFile;

if (!signingIn &&
!gettingStarted &&
(!showingAnonymousRoute || state is ProfileLoggingOut)) {
signingIn = true;
notifyListeners();
}

// Redirect the user away from sign in if they are already signed in.
if (signingIn && state is ProfileLoggedIn) {
if ((signingIn || gettingStarted) && state is ProfileLoggedIn) {
signingIn = false;
gettingStarted = false;
notifyListeners();
}

// Cleans up any shared drives from previous sessions
// TODO: Find a better place to do this
final lastLoggedInUser =
Expand Down Expand Up @@ -136,6 +142,8 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
);
} else if (signingIn) {
shell = const LoginPage();
} else if (gettingStarted) {
shell = const LoginPage(gettingStarted: true);
} else if (state is ProfileLoggedIn || anonymouslyShowDriveDetail) {
shell = BlocConsumer<DrivesCubit, DrivesState>(
listener: (context, state) {
Expand Down Expand Up @@ -308,6 +316,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
@override
Future<void> setNewRoutePath(AppRoutePath configuration) async {
signingIn = configuration.signingIn;
gettingStarted = configuration.getStarted;
driveId = configuration.driveId;
driveName = configuration.driveName;
driveFolderId = configuration.driveFolderId;
Expand All @@ -320,6 +329,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>

void clearState() {
signingIn = true;
gettingStarted = false;
driveId = null;
driveName = null;
driveFolderId = null;
Expand Down

0 comments on commit 08a2d25

Please sign in to comment.