diff --git a/app_flowy/lib/user/presentation/skip_log_in_screen.dart b/app_flowy/lib/user/presentation/skip_log_in_screen.dart index 86c8afe1da..4bb48118b2 100644 --- a/app_flowy/lib/user/presentation/skip_log_in_screen.dart +++ b/app_flowy/lib/user/presentation/skip_log_in_screen.dart @@ -8,9 +8,13 @@ import 'package:flowy_infra/uuid.dart'; import 'package:flowy_infra_ui/widget/rounded_button.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flowy_log/flowy_log.dart'; +import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace-infra/workspace_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:dartz/dartz.dart' as dartz; class SkipLogInScreen extends StatefulWidget { final IAuthRouter router; @@ -95,9 +99,36 @@ class _SkipLogInScreenState extends State { final result = await widget.authManager.signUp("FlowyUser", password, userEmail); result.fold( (user) { + WorkspaceEventReadCurWorkspace().send().then((result) { + _openCurrentWorkspace(context, user, result); + }); userListener = getIt(param1: user); + userListener!.workspaceUpdatedNotifier.addPublishListener((result) { + result.fold( + (workspace) { + assert(workspace.length == 1); + if (workspace.isNotEmpty) { + _openCurrentWorkspace(context, user, dartz.left(workspace[0])); + } + }, + (error) => _openCurrentWorkspace(context, user, dartz.right(error)), + ); + }); + }, + (error) { + Log.error(error); + }, + ); + } - // router.pushHomeScreen(context, newUser.profile, newUser.workspaceId); + void _openCurrentWorkspace( + BuildContext context, + UserProfile user, + dartz.Either workspacesOrError, + ) { + workspacesOrError.fold( + (workspace) { + widget.router.pushHomeScreen(context, user, workspace.id); }, (error) { Log.error(error); diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart index dd63f8d570..d8be5bca69 100644 --- a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart +++ b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart @@ -101,20 +101,6 @@ class WorkspaceEventReadWorkspaceApps { } } -class WorkspaceEventCreateDefaultWorkspace { - WorkspaceEventCreateDefaultWorkspace(); - - Future> send() { - final request = FFIRequest.create() - ..event = WorkspaceEvent.CreateDefaultWorkspace.toString(); - - return Dispatch.asyncRequest(request).then((bytesResult) => bytesResult.fold( - (okBytes) => left(WorkspaceIdentifier.fromBuffer(okBytes)), - (errBytes) => right(WorkspaceError.fromBuffer(errBytes)), - )); - } -} - class WorkspaceEventCreateApp { CreateAppRequest request; WorkspaceEventCreateApp(this.request); diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs index 368268dd97..08a218edea 100644 --- a/rust-lib/flowy-sdk/src/lib.rs +++ b/rust-lib/flowy-sdk/src/lib.rs @@ -114,7 +114,7 @@ fn listen_on_user_status_changed( workspace_controller.user_session_expired(); }, UserStatus::SignUp { .. } => { - workspace_controller.user_did_sign_up().await; + let _ = workspace_controller.user_did_sign_up().await; }, }, Err(_) => {}, diff --git a/rust-lib/flowy-workspace/src/event.rs b/rust-lib/flowy-workspace/src/event.rs index e4b0c7756e..9097b25c18 100644 --- a/rust-lib/flowy-workspace/src/event.rs +++ b/rust-lib/flowy-workspace/src/event.rs @@ -22,9 +22,6 @@ pub enum WorkspaceEvent { #[event(input = "QueryWorkspaceRequest", output = "RepeatedApp")] ReadWorkspaceApps = 5, - #[event(output = "WorkspaceIdentifier")] - CreateDefaultWorkspace = 6, - #[event(input = "CreateAppRequest", output = "App")] CreateApp = 101, diff --git a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs index c38d4690f9..5ed0707da5 100644 --- a/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs +++ b/rust-lib/flowy-workspace/src/handlers/workspace_handler.rs @@ -43,31 +43,6 @@ pub(crate) async fn read_workspace_apps_handler( data_result(repeated_app) } -#[tracing::instrument(skip(workspace_controller, app_controller, view_controller), err)] -pub(crate) async fn create_default_workspace_handler( - workspace_controller: Unit>, - app_controller: Unit>, - view_controller: Unit>, -) -> DataResult { - let time = Utc::now(); - let mut workspace = user_default::create_default_workspace(time); - let workspace_id = workspace.id.clone(); - let apps = workspace.take_apps().into_inner(); - - let _ = workspace_controller.create_workspace(workspace).await?; - for mut app in apps { - let views = app.take_belongings().into_inner(); - let _ = app_controller.create_app(app).await?; - for view in views { - let _ = view_controller.create_view(view).await?; - } - } - - data_result(WorkspaceIdentifier { - workspace_id: Some(workspace_id), - }) -} - #[tracing::instrument(skip(data, controller), err)] pub(crate) async fn read_workspaces_handler( data: Data, diff --git a/rust-lib/flowy-workspace/src/module.rs b/rust-lib/flowy-workspace/src/module.rs index 84e3081ccb..2dd9e30aff 100644 --- a/rust-lib/flowy-workspace/src/module.rs +++ b/rust-lib/flowy-workspace/src/module.rs @@ -78,8 +78,7 @@ pub fn create(workspace: Arc) -> Module { .event(WorkspaceEvent::ReadCurWorkspace, read_cur_workspace_handler) .event(WorkspaceEvent::ReadWorkspaces, read_workspaces_handler) .event(WorkspaceEvent::OpenWorkspace, open_workspace_handler) - .event(WorkspaceEvent::ReadWorkspaceApps, read_workspace_apps_handler) - .event(WorkspaceEvent::CreateDefaultWorkspace, create_default_workspace_handler); + .event(WorkspaceEvent::ReadWorkspaceApps, read_workspace_apps_handler); module = module .event(WorkspaceEvent::CreateApp, create_app_handler) diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index caa887b2f0..8d59206e76 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -58,11 +58,12 @@ impl WorkspaceController { pub fn user_session_expired(&self) {} - pub async fn user_did_sign_up(&self) { + pub async fn user_did_sign_up(&self) -> WorkspaceResult<()> { log::debug!("Create user default workspace"); let time = Utc::now(); let mut workspace = user_default::create_default_workspace(time); let apps = workspace.take_apps().into_inner(); + let cloned_workspace = workspace.clone(); let _ = self.create_workspace(workspace).await?; for mut app in apps { @@ -73,17 +74,14 @@ impl WorkspaceController { } } - match self.user.token() { - Ok(token) => { - let repeated_workspace = RepeatedWorkspace { items: vec![workspace] }; - send_dart_notification(&token, WorkspaceNotification::UserCreateWorkspace) - .payload(repeated_workspace) - .send(); - }, - Err(e) => { - log::error!("{:?}", e); - }, - } + let token = self.user.token()?; + let repeated_workspace = RepeatedWorkspace { + items: vec![cloned_workspace], + }; + send_dart_notification(&token, WorkspaceNotification::UserCreateWorkspace) + .payload(repeated_workspace) + .send(); + Ok(()) } pub(crate) async fn create_workspace_from_params(