2021-07-25 18:04:16 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
|
|
|
import 'package:app_flowy/user/domain/i_auth.dart';
|
2021-07-13 13:14:49 +08:00
|
|
|
import 'package:app_flowy/user/presentation/sign_in/sign_in_screen.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:app_flowy/welcome/domain/auth_state.dart';
|
2021-07-21 15:43:05 +08:00
|
|
|
import 'package:app_flowy/welcome/domain/i_welcome.dart';
|
2021-08-30 16:18:58 +08:00
|
|
|
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/home/home_screen.dart';
|
2021-08-30 16:18:58 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/workspace/workspace_select_screen.dart';
|
|
|
|
import 'package:flowy_infra/time/duration.dart';
|
|
|
|
import 'package:flowy_infra_ui/widget/route/animation.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
2021-07-13 14:28:01 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
|
2021-08-31 11:32:51 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart' as workspace;
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
2021-07-21 15:43:05 +08:00
|
|
|
export 'package:app_flowy/welcome/domain/i_welcome.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
|
|
|
|
class WelcomeAuthImpl implements IWelcomeAuth {
|
|
|
|
@override
|
2021-07-26 11:51:39 +08:00
|
|
|
Future<AuthState> currentUserDetail() {
|
2021-07-12 23:27:58 +08:00
|
|
|
final result = UserEventGetStatus().send();
|
|
|
|
return result.then((result) {
|
|
|
|
return result.fold(
|
|
|
|
(userDetail) {
|
|
|
|
return AuthState.authenticated(userDetail);
|
|
|
|
},
|
|
|
|
(userError) {
|
|
|
|
return AuthState.unauthenticated(userError);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class WelcomeRoute implements IWelcomeRoute {
|
|
|
|
@override
|
2021-08-30 16:18:58 +08:00
|
|
|
Future<void> pushHomeScreen(BuildContext context, UserDetail user) async {
|
|
|
|
final repo = UserRepo(user: user);
|
|
|
|
return WorkspaceEventReadCurWorkspace().send().then(
|
|
|
|
(result) {
|
|
|
|
return result.fold(
|
|
|
|
(workspace) =>
|
|
|
|
_pushToScreen(context, HomeScreen(repo.user, workspace.id)),
|
|
|
|
(error) async {
|
2021-08-31 11:32:51 +08:00
|
|
|
assert(error.code == workspace.ErrorCode.CurrentWorkspaceNotFound);
|
2021-08-30 16:18:58 +08:00
|
|
|
final screen = WorkspaceSelectScreen(repo: repo);
|
|
|
|
final workspaceId = await Navigator.of(context).push(
|
|
|
|
PageRoutes.fade(
|
|
|
|
() => screen,
|
|
|
|
RouteDurations.slow.inMilliseconds * .001,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
_pushToScreen(context, HomeScreen(repo.user, workspaceId));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget pushSignInScreen() {
|
2021-07-25 18:04:16 +08:00
|
|
|
return SignInScreen(router: getIt<IAuthRouter>());
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|
2021-08-30 16:18:58 +08:00
|
|
|
|
|
|
|
void _pushToScreen(BuildContext context, Widget screen) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
PageRoutes.fade(
|
|
|
|
() => screen, RouteDurations.slow.inMilliseconds * .001));
|
|
|
|
}
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|