Skip to content

Commit db2e231

Browse files
authored
feat: support canceling the sign-in event (#4342)
1 parent dcb0709 commit db2e231

File tree

5 files changed

+128
-93
lines changed

5 files changed

+128
-93
lines changed

frontend/appflowy_flutter/lib/user/application/sign_in_bloc.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import 'package:appflowy/env/cloud_env.dart';
22
import 'package:appflowy/startup/startup.dart';
33
import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart';
44
import 'package:appflowy/user/application/auth/auth_service.dart';
5-
import 'package:dartz/dartz.dart';
65
import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart';
76
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
87
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
98
show UserProfilePB;
10-
import 'package:freezed_annotation/freezed_annotation.dart';
9+
import 'package:dartz/dartz.dart';
1110
import 'package:flutter_bloc/flutter_bloc.dart';
11+
import 'package:freezed_annotation/freezed_annotation.dart';
1212

1313
part 'sign_in_bloc.freezed.dart';
1414

@@ -105,6 +105,16 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
105105
}
106106
}
107107
},
108+
cancel: (value) {
109+
emit(
110+
state.copyWith(
111+
isSubmitting: false,
112+
emailError: none(),
113+
passwordError: none(),
114+
successOrFail: none(),
115+
),
116+
);
117+
},
108118
);
109119
});
110120
}
@@ -245,6 +255,7 @@ class SignInEvent with _$SignInEvent {
245255
const factory SignInEvent.passwordChanged(String password) = PasswordChanged;
246256
const factory SignInEvent.deepLinkStateChange(DeepLinkResult result) =
247257
_DeepLinkStateChange;
258+
const factory SignInEvent.cancel() = _Cancel;
248259
}
249260

250261
@freezed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:appflowy/generated/locale_keys.g.dart';
2+
import 'package:appflowy/mobile/presentation/base/app_bar_actions.dart';
3+
import 'package:appflowy/user/application/sign_in_bloc.dart';
4+
import 'package:easy_localization/easy_localization.dart';
5+
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_bloc/flutter_bloc.dart';
8+
9+
class MobileLoadingScreen extends StatelessWidget {
10+
const MobileLoadingScreen({
11+
super.key,
12+
});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
const double spacing = 16;
17+
18+
return Scaffold(
19+
appBar: AppBar(
20+
leading: AppBarCloseButton(
21+
onTap: () => context.read<SignInBloc>().add(
22+
const SignInEvent.cancel(),
23+
),
24+
),
25+
elevation: 0,
26+
),
27+
body: Center(
28+
child: Column(
29+
mainAxisAlignment: MainAxisAlignment.center,
30+
children: [
31+
FlowyText(LocaleKeys.signIn_signingInText.tr()),
32+
const VSpace(spacing),
33+
const CircularProgressIndicator(),
34+
],
35+
),
36+
),
37+
);
38+
}
39+
}

frontend/appflowy_flutter/lib/user/presentation/screens/sign_in_screen/mobile_sign_in_screen.dart

Lines changed: 70 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,89 @@ import 'package:appflowy/env/cloud_env.dart';
22
import 'package:appflowy/generated/flowy_svgs.g.dart';
33
import 'package:appflowy/generated/locale_keys.g.dart';
44
import 'package:appflowy/user/presentation/screens/sign_in_screen/widgets/widgets.dart';
5-
import 'package:appflowy_editor/appflowy_editor.dart';
65
import 'package:easy_localization/easy_localization.dart';
76
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
7+
import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
99

1010
class MobileSignInScreen extends StatelessWidget {
11-
const MobileSignInScreen({super.key, required this.isLoading});
12-
final bool isLoading;
11+
const MobileSignInScreen({
12+
super.key,
13+
});
1314

1415
@override
1516
Widget build(BuildContext context) {
1617
const double spacing = 16;
17-
// Welcome to Appflowy
18-
final welcomeString = LocaleKeys.welcomeText.tr();
19-
final style = Theme.of(context);
18+
final colorScheme = Theme.of(context).colorScheme;
2019
return Scaffold(
21-
resizeToAvoidBottomInset: false,
22-
body: isLoading
23-
? // TODO(yijing): improve loading effect in the future
24-
const Center(
25-
child: Column(
26-
mainAxisAlignment: MainAxisAlignment.center,
27-
children: [
28-
Text('Signing in...'),
29-
VSpace(spacing),
30-
CircularProgressIndicator(),
31-
],
32-
),
33-
)
34-
: Padding(
35-
padding: const EdgeInsets.fromLTRB(50, 0, 50, 30),
36-
child: Column(
37-
children: [
38-
const Spacer(
39-
flex: 4,
40-
),
41-
const FlowySvg(
42-
FlowySvgs.flowy_logo_xl,
43-
size: Size.square(64),
44-
blendMode: null,
45-
),
46-
const VSpace(spacing * 2),
47-
// Welcome to
48-
Text(
49-
welcomeString.substring(0, welcomeString.length - 8),
50-
style: style.textTheme.displayMedium,
51-
textAlign: TextAlign.center,
52-
),
53-
// Appflowy
54-
Text(
55-
welcomeString.substring(welcomeString.length - 8),
56-
style: style.textTheme.displayLarge,
57-
textAlign: TextAlign.center,
58-
),
59-
const VSpace(spacing),
60-
// TODO(yijing): confirm the subtitle before release app
61-
Text(
62-
'You are in charge of your data and customizations.',
63-
style: style.textTheme.bodyMedium?.copyWith(
64-
color: style.colorScheme.onSecondary,
65-
),
66-
textAlign: TextAlign.center,
67-
),
68-
const Spacer(
69-
flex: 2,
70-
),
71-
if (!PlatformExtension.isMobile) ...[
72-
const SignInAnonymousButton(),
73-
const VSpace(spacing),
74-
],
75-
if (isAuthEnabled) ...[
76-
if (!PlatformExtension.isMobile) ...[
77-
Row(
78-
mainAxisAlignment: MainAxisAlignment.center,
79-
children: [
80-
const Expanded(child: Divider()),
81-
Padding(
82-
padding: const EdgeInsets.symmetric(horizontal: 8),
83-
child: Text(
84-
LocaleKeys.signIn_or.tr(),
85-
style: style.textTheme.bodyMedium?.copyWith(
86-
color: style.colorScheme.onSecondary,
87-
),
88-
),
89-
),
90-
const Expanded(child: Divider()),
91-
],
20+
body: Padding(
21+
padding: const EdgeInsets.symmetric(vertical: 50, horizontal: 40),
22+
child: Column(
23+
children: [
24+
const Spacer(
25+
flex: 4,
26+
),
27+
const FlowySvg(
28+
FlowySvgs.flowy_logo_xl,
29+
size: Size.square(64),
30+
blendMode: null,
31+
),
32+
const VSpace(spacing * 2),
33+
// Welcome to
34+
FlowyText(
35+
LocaleKeys.welcomeTo.tr(),
36+
textAlign: TextAlign.center,
37+
fontSize: 32,
38+
fontWeight: FontWeight.w700,
39+
),
40+
// AppFlowy
41+
FlowyText(
42+
LocaleKeys.appName.tr(),
43+
textAlign: TextAlign.center,
44+
fontSize: 32,
45+
color: const Color(0xFF00BCF0),
46+
fontWeight: FontWeight.w700,
47+
),
48+
const VSpace(spacing),
49+
const Spacer(
50+
flex: 2,
51+
),
52+
53+
// disable anonymous sign in release mode.
54+
if (kDebugMode) ...[
55+
const SignInAnonymousButton(),
56+
const VSpace(spacing),
57+
],
58+
59+
// if the cloud env is enabled, show the third-party sign in buttons.
60+
if (isAuthEnabled) ...[
61+
if (kDebugMode) ...[
62+
Row(
63+
mainAxisAlignment: MainAxisAlignment.center,
64+
children: [
65+
const Expanded(child: Divider()),
66+
Padding(
67+
padding: const EdgeInsets.symmetric(horizontal: 8),
68+
child: FlowyText(
69+
LocaleKeys.signIn_or.tr(),
70+
color: colorScheme.onSecondary,
9271
),
93-
const VSpace(spacing),
94-
],
95-
const ThirdPartySignInButtons(),
96-
],
97-
if (!isAuthEnabled)
98-
const Spacer(
99-
flex: 2,
10072
),
101-
const VSpace(spacing),
102-
],
73+
const Expanded(child: Divider()),
74+
],
75+
),
76+
const VSpace(spacing),
77+
],
78+
const ThirdPartySignInButtons(),
79+
],
80+
if (!isAuthEnabled)
81+
const Spacer(
82+
flex: 2,
10383
),
104-
),
84+
const VSpace(spacing),
85+
],
86+
),
87+
),
10588
);
10689
}
10790
}

frontend/appflowy_flutter/lib/user/presentation/screens/sign_in_screen/sign_in_screen.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:appflowy/startup/startup.dart';
22
import 'package:appflowy/user/application/sign_in_bloc.dart';
33
import 'package:appflowy/user/presentation/router.dart';
44
import 'package:appflowy/user/presentation/screens/sign_in_screen/desktop_sign_in_screen.dart';
5+
import 'package:appflowy/user/presentation/screens/sign_in_screen/mobile_loading_screen.dart';
56
import 'package:appflowy/user/presentation/screens/sign_in_screen/mobile_sign_in_screen.dart';
67
import 'package:appflowy_editor/appflowy_editor.dart';
78
import 'package:flutter/material.dart';
@@ -32,12 +33,11 @@ class SignInScreen extends StatelessWidget {
3233
);
3334
},
3435
builder: (context, state) {
35-
// When user is logining through 3rd party, a loading widget will appear on the screen. [isLoading] is used to control it is on or not.
3636
final isLoading = context.read<SignInBloc>().state.isSubmitting;
3737
if (PlatformExtension.isMobile) {
38-
return MobileSignInScreen(
39-
isLoading: isLoading,
40-
);
38+
return isLoading
39+
? const MobileLoadingScreen()
40+
: const MobileSignInScreen();
4141
}
4242
return DesktopSignInScreen(
4343
isLoading: isLoading,

frontend/resources/translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"appName": "AppFlowy",
33
"defaultUsername": "Me",
44
"welcomeText": "Welcome to @:appName",
5+
"welcomeTo": "Welcome to",
56
"githubStarText": "Star on GitHub",
67
"subscribeNewsletterText": "Subscribe to Newsletter",
78
"letsGoButtonText": "Quick Start",
@@ -35,6 +36,7 @@
3536
"loginStartWithAnonymous": "Start with an anonymous session",
3637
"continueAnonymousUser": "Continue with an anonymous session",
3738
"buttonText": "Sign In",
39+
"signingInText": "Signing in...",
3840
"forgotPassword": "Forgot Password?",
3941
"emailHint": "Email",
4042
"passwordHint": "Password",

0 commit comments

Comments
 (0)