[flutter]: finish let's go feature

This commit is contained in:
appflowy 2021-11-09 11:07:20 +08:00
parent 7f3bd45487
commit d8fad4a2f3
7 changed files with 44 additions and 58 deletions

View File

@ -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<SkipLogInScreen> {
final result = await widget.authManager.signUp("FlowyUser", password, userEmail);
result.fold(
(user) {
WorkspaceEventReadCurWorkspace().send().then((result) {
_openCurrentWorkspace(context, user, result);
});
userListener = getIt<IUserListener>(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<Workspace, WorkspaceError> workspacesOrError,
) {
workspacesOrError.fold(
(workspace) {
widget.router.pushHomeScreen(context, user, workspace.id);
},
(error) {
Log.error(error);

View File

@ -101,20 +101,6 @@ class WorkspaceEventReadWorkspaceApps {
}
}
class WorkspaceEventCreateDefaultWorkspace {
WorkspaceEventCreateDefaultWorkspace();
Future<Either<WorkspaceIdentifier, WorkspaceError>> 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);

View File

@ -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(_) => {},

View File

@ -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,

View File

@ -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<Arc<WorkspaceController>>,
app_controller: Unit<Arc<AppController>>,
view_controller: Unit<Arc<ViewController>>,
) -> DataResult<WorkspaceIdentifier, WorkspaceError> {
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<QueryWorkspaceRequest>,

View File

@ -78,8 +78,7 @@ pub fn create(workspace: Arc<WorkspaceController>) -> 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)

View File

@ -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(