2023-09-28 06:17:38 +00:00
|
|
|
import 'package:appflowy/mobile/presentation/home/mobile_home_page.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-09-12 02:32:26 +00:00
|
|
|
import 'package:appflowy/user/presentation/screens/screens.dart';
|
2023-09-28 06:17:38 +00:00
|
|
|
import 'package:appflowy/workspace/presentation/home/desktop_home_screen.dart';
|
2023-01-12 14:31:39 +00:00
|
|
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
2023-08-21 16:19:15 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
|
|
|
|
show UserProfilePB;
|
2023-12-30 23:29:40 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
|
2023-12-15 10:20:44 +00:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
2021-07-25 10:04:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-28 06:17:38 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-08-07 14:24:04 +00:00
|
|
|
|
2022-01-31 00:15:49 +00:00
|
|
|
class AuthRouter {
|
2022-11-09 03:07:29 +00:00
|
|
|
void pushForgetPasswordScreen(BuildContext context) {}
|
2021-07-25 10:04:16 +00:00
|
|
|
|
2023-09-12 02:32:26 +00:00
|
|
|
void pushWorkspaceStartScreen(
|
|
|
|
BuildContext context,
|
|
|
|
UserProfilePB userProfile,
|
|
|
|
) {
|
|
|
|
getIt<SplashRouter>().pushWorkspaceStartScreen(context, userProfile);
|
2021-07-25 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
void pushSignUpScreen(BuildContext context) {
|
2023-09-28 06:17:38 +00:00
|
|
|
context.push(SignUpScreen.routeName);
|
2021-11-08 11:19:02 +00:00
|
|
|
}
|
2023-05-21 10:53:59 +00:00
|
|
|
|
2023-09-12 02:32:26 +00: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 06:17:38 +00:00
|
|
|
Future<void> goHomeScreen(
|
2023-05-21 10:53:59 +00:00
|
|
|
BuildContext context,
|
|
|
|
UserProfilePB userProfile,
|
|
|
|
) async {
|
2023-11-01 03:45:35 +00:00
|
|
|
final result = await FolderEventGetCurrentWorkspaceSetting().send();
|
2023-05-21 10:53:59 +00:00
|
|
|
result.fold(
|
2023-09-12 02:32:26 +00:00
|
|
|
(workspaceSetting) {
|
2023-09-28 06:17:38 +00: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-12 02:32:26 +00:00
|
|
|
if (PlatformExtension.isMobile) {
|
2023-09-28 06:17:38 +00:00
|
|
|
context.go(
|
|
|
|
MobileHomeScreen.routeName,
|
2023-09-12 02:32:26 +00:00
|
|
|
);
|
|
|
|
} else {
|
2023-09-28 06:17:38 +00:00
|
|
|
context.go(
|
|
|
|
DesktopHomeScreen.routeName,
|
2023-09-12 02:32:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(error) => pushWorkspaceStartScreen(context, userProfile),
|
2023-05-21 10:53:59 +00:00
|
|
|
);
|
|
|
|
}
|
2023-08-17 15:46:39 +00:00
|
|
|
|
2024-01-29 02:26:45 +00:00
|
|
|
void pushEncryptionScreen(
|
2023-08-17 15:46:39 +00:00
|
|
|
BuildContext context,
|
|
|
|
UserProfilePB userProfile,
|
2024-01-29 02:26:45 +00:00
|
|
|
) {
|
2023-09-28 06:17:38 +00: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 15:46:39 +00:00
|
|
|
);
|
|
|
|
}
|
2023-08-21 16:19:15 +00:00
|
|
|
|
|
|
|
Future<void> pushWorkspaceErrorScreen(
|
|
|
|
BuildContext context,
|
|
|
|
UserFolderPB userFolder,
|
|
|
|
FlowyError error,
|
|
|
|
) async {
|
2023-09-28 06:17:38 +00:00
|
|
|
await context.push(
|
|
|
|
WorkspaceErrorScreen.routeName,
|
|
|
|
extra: {
|
|
|
|
WorkspaceErrorScreen.argUserFolder: userFolder,
|
|
|
|
WorkspaceErrorScreen.argError: error,
|
|
|
|
},
|
2023-08-21 16:19:15 +00:00
|
|
|
);
|
|
|
|
}
|
2021-07-25 10:04:16 +00:00
|
|
|
}
|
2022-01-31 00:24:29 +00:00
|
|
|
|
2023-09-12 02:32:26 +00:00
|
|
|
class SplashRouter {
|
2023-09-28 06:17:38 +00: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-12 02:32:26 +00:00
|
|
|
Future<void> pushWorkspaceStartScreen(
|
2023-01-12 14:31:39 +00:00
|
|
|
BuildContext context,
|
|
|
|
UserProfilePB userProfile,
|
|
|
|
) async {
|
2023-09-28 06:17:38 +00:00
|
|
|
await context.push(
|
|
|
|
WorkspaceStartScreen.routeName,
|
|
|
|
extra: {
|
|
|
|
WorkspaceStartScreen.argUserProfile: userProfile,
|
|
|
|
},
|
2022-01-31 00:24:29 +00:00
|
|
|
);
|
|
|
|
|
2024-01-29 02:26:45 +00:00
|
|
|
final result = await FolderEventGetCurrentWorkspaceSetting().send();
|
|
|
|
result.fold(
|
|
|
|
(workspaceSettingPB) => pushHomeScreen(context),
|
|
|
|
(r) => null,
|
|
|
|
);
|
2022-01-31 00:24:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 14:31:39 +00:00
|
|
|
void pushHomeScreen(
|
|
|
|
BuildContext context,
|
|
|
|
) {
|
2023-09-12 02:32:26 +00:00
|
|
|
if (PlatformExtension.isMobile) {
|
2023-09-28 06:17:38 +00:00
|
|
|
context.push(
|
|
|
|
MobileHomeScreen.routeName,
|
2023-09-12 02:32:26 +00:00
|
|
|
);
|
|
|
|
} else {
|
2023-09-28 06:17:38 +00:00
|
|
|
context.push(
|
|
|
|
DesktopHomeScreen.routeName,
|
2023-09-12 02:32:26 +00:00
|
|
|
);
|
|
|
|
}
|
2022-01-31 00:24:29 +00:00
|
|
|
}
|
|
|
|
|
2023-09-28 06:17:38 +00:00
|
|
|
void goHomeScreen(
|
|
|
|
BuildContext context,
|
|
|
|
) {
|
|
|
|
if (PlatformExtension.isMobile) {
|
|
|
|
context.go(
|
|
|
|
MobileHomeScreen.routeName,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
context.go(
|
|
|
|
DesktopHomeScreen.routeName,
|
|
|
|
);
|
|
|
|
}
|
2022-01-31 00:24:29 +00:00
|
|
|
}
|
|
|
|
}
|