| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  | import 'package:appflowy/mobile/presentation/home/mobile_home_page.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/startup/startup.dart'; | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  | import 'package:appflowy/user/presentation/screens/screens.dart'; | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  | import 'package:appflowy/workspace/presentation/home/desktop_home_screen.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-12 22:31:39 +08:00
										 |  |  | import 'package:appflowy_backend/dispatch/dispatch.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-22 00:19:15 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-08 12:10:53 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart' | 
					
						
							|  |  |  |     show UserProfilePB; | 
					
						
							| 
									
										
										
										
											2023-12-31 07:29:40 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-15 18:20:44 +08:00
										 |  |  | import 'package:appflowy_editor/appflowy_editor.dart'; | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  | import 'package:go_router/go_router.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-07 22:24:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 08:15:49 +08:00
										 |  |  | class AuthRouter { | 
					
						
							| 
									
										
										
										
											2022-11-09 11:07:29 +08:00
										 |  |  |   void pushForgetPasswordScreen(BuildContext context) {} | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |   void pushWorkspaceStartScreen( | 
					
						
							|  |  |  |     BuildContext context, | 
					
						
							|  |  |  |     UserProfilePB userProfile, | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     getIt<SplashRouter>().pushWorkspaceStartScreen(context, userProfile); | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-06 16:18:34 +08:00
										 |  |  |   void pushSignUpScreen(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |     context.push(SignUpScreen.routeName); | 
					
						
							| 
									
										
										
										
											2021-11-08 19:19:02 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |   /// Navigates to the home screen based on the current workspace and platform.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// This function takes in a [BuildContext] and a [UserProfilePB] object to
 | 
					
						
							|  |  |  |   /// determine the user's settings and then navigate to the appropriate home screen
 | 
					
						
							|  |  |  |   /// (`MobileHomeScreen` for mobile platforms, `DesktopHomeScreen` for others).
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// It first fetches the current workspace settings using [FolderEventGetCurrentWorkspace].
 | 
					
						
							|  |  |  |   /// If the workspace settings are successfully fetched, it navigates to the home screen.
 | 
					
						
							|  |  |  |   /// If there's an error, it defaults to the workspace start screen.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// @param [context] BuildContext for navigating to the appropriate screen.
 | 
					
						
							|  |  |  |   /// @param [userProfile] UserProfilePB object containing the details of the current user.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |   Future<void> goHomeScreen( | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |     BuildContext context, | 
					
						
							|  |  |  |     UserProfilePB userProfile, | 
					
						
							|  |  |  |   ) async { | 
					
						
							| 
									
										
										
										
											2023-11-01 11:45:35 +08:00
										 |  |  |     final result = await FolderEventGetCurrentWorkspaceSetting().send(); | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |     result.fold( | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |       (workspaceSetting) { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |         // Replace SignInScreen or SkipLogInScreen as root page.
 | 
					
						
							|  |  |  |         // If user click back button, it will exit app rather than go back to SignInScreen or SkipLogInScreen
 | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |         if (PlatformExtension.isMobile) { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |           context.go( | 
					
						
							|  |  |  |             MobileHomeScreen.routeName, | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |           ); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |           context.go( | 
					
						
							|  |  |  |             DesktopHomeScreen.routeName, | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |           ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       (error) => pushWorkspaceStartScreen(context, userProfile), | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 10:26:45 +08:00
										 |  |  |   void pushEncryptionScreen( | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |     BuildContext context, | 
					
						
							|  |  |  |     UserProfilePB userProfile, | 
					
						
							| 
									
										
										
										
											2024-01-29 10:26:45 +08:00
										 |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |     // After log in,push EncryptionScreen on the top SignInScreen
 | 
					
						
							|  |  |  |     context.push( | 
					
						
							|  |  |  |       EncryptSecretScreen.routeName, | 
					
						
							|  |  |  |       extra: { | 
					
						
							|  |  |  |         EncryptSecretScreen.argUser: userProfile, | 
					
						
							|  |  |  |         EncryptSecretScreen.argKey: ValueKey(userProfile.id), | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-08-22 00:19:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Future<void> pushWorkspaceErrorScreen( | 
					
						
							|  |  |  |     BuildContext context, | 
					
						
							|  |  |  |     UserFolderPB userFolder, | 
					
						
							|  |  |  |     FlowyError error, | 
					
						
							|  |  |  |   ) async { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |     await context.push( | 
					
						
							|  |  |  |       WorkspaceErrorScreen.routeName, | 
					
						
							|  |  |  |       extra: { | 
					
						
							|  |  |  |         WorkspaceErrorScreen.argUserFolder: userFolder, | 
					
						
							|  |  |  |         WorkspaceErrorScreen.argError: error, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2023-08-22 00:19:15 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-31 08:24:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  | class SplashRouter { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |   // Unused for now, it was planed to be used in SignUpScreen.
 | 
					
						
							|  |  |  |   // To let user choose workspace than navigate to corresponding home screen.
 | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |   Future<void> pushWorkspaceStartScreen( | 
					
						
							| 
									
										
										
										
											2023-01-12 22:31:39 +08:00
										 |  |  |     BuildContext context, | 
					
						
							|  |  |  |     UserProfilePB userProfile, | 
					
						
							|  |  |  |   ) async { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |     await context.push( | 
					
						
							|  |  |  |       WorkspaceStartScreen.routeName, | 
					
						
							|  |  |  |       extra: { | 
					
						
							|  |  |  |         WorkspaceStartScreen.argUserProfile: userProfile, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-01-31 08:24:29 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 10:26:45 +08:00
										 |  |  |     final result = await FolderEventGetCurrentWorkspaceSetting().send(); | 
					
						
							|  |  |  |     result.fold( | 
					
						
							|  |  |  |       (workspaceSettingPB) => pushHomeScreen(context), | 
					
						
							|  |  |  |       (r) => null, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2022-01-31 08:24:29 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-12 22:31:39 +08:00
										 |  |  |   void pushHomeScreen( | 
					
						
							|  |  |  |     BuildContext context, | 
					
						
							|  |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |     if (PlatformExtension.isMobile) { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |       context.push( | 
					
						
							|  |  |  |         MobileHomeScreen.routeName, | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |       context.push( | 
					
						
							|  |  |  |         DesktopHomeScreen.routeName, | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-31 08:24:29 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-28 01:17:38 -05:00
										 |  |  |   void goHomeScreen( | 
					
						
							|  |  |  |     BuildContext context, | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     if (PlatformExtension.isMobile) { | 
					
						
							|  |  |  |       context.go( | 
					
						
							|  |  |  |         MobileHomeScreen.routeName, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       context.go( | 
					
						
							|  |  |  |         DesktopHomeScreen.routeName, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-31 08:24:29 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |