From 7fa15615dfbaca498269bfc4ed66b8292d63d29b Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:19:04 +0800 Subject: [PATCH] chore: enable continue last session after logout (#3253) --- .../lib/user/presentation/sign_in_screen.dart | 15 ++--- .../user/presentation/skip_log_in_screen.dart | 61 ++++++++++++++----- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/frontend/appflowy_flutter/lib/user/presentation/sign_in_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/sign_in_screen.dart index 64b7447d39..94f34f048c 100644 --- a/frontend/appflowy_flutter/lib/user/presentation/sign_in_screen.dart +++ b/frontend/appflowy_flutter/lib/user/presentation/sign_in_screen.dart @@ -238,14 +238,8 @@ class SignInAsGuestButton extends StatelessWidget { child: BlocBuilder( builder: (context, state) { final text = state.historicalUsers.isEmpty - ? FlowyText.medium( - LocaleKeys.signIn_loginAsGuestButtonText.tr(), - textAlign: TextAlign.center, - ) - : FlowyText.medium( - LocaleKeys.signIn_continueAnonymousUser.tr(), - textAlign: TextAlign.center, - ); + ? LocaleKeys.signIn_loginAsGuestButtonText.tr() + : LocaleKeys.signIn_continueAnonymousUser.tr(); final onTap = state.historicalUsers.isEmpty ? () { @@ -265,7 +259,10 @@ class SignInAsGuestButton extends StatelessWidget { child: FlowyButton( isSelected: true, disable: signInState.isSubmitting, - text: text, + text: FlowyText.medium( + text, + textAlign: TextAlign.center, + ), radius: Corners.s6Border, onTap: onTap, ), diff --git a/frontend/appflowy_flutter/lib/user/presentation/skip_log_in_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/skip_log_in_screen.dart index ea00915cbc..e1031e3f6e 100644 --- a/frontend/appflowy_flutter/lib/user/presentation/skip_log_in_screen.dart +++ b/frontend/appflowy_flutter/lib/user/presentation/skip_log_in_screen.dart @@ -4,6 +4,7 @@ import 'package:appflowy/startup/entry_point.dart'; import 'package:appflowy/startup/launch_configuration.dart'; import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/user/application/auth/auth_service.dart'; +import 'package:appflowy/user/application/historical_user_bloc.dart'; import 'package:appflowy/workspace/application/appearance.dart'; import 'package:appflowy/workspace/presentation/settings/widgets/settings_language_view.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; @@ -19,7 +20,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart'; import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:google_fonts/google_fonts.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../generated/locale_keys.g.dart'; @@ -289,21 +289,52 @@ class GoButton extends StatelessWidget { @override Widget build(BuildContext context) { - return FlowyTextButton( - LocaleKeys.letsGoButtonText.tr(), - constraints: const BoxConstraints( - maxWidth: 340, - maxHeight: 48, + return BlocProvider( + create: (context) => HistoricalUserBloc() + ..add( + const HistoricalUserEvent.initial(), + ), + child: BlocListener( + listenWhen: (previous, current) => + previous.openedHistoricalUser != current.openedHistoricalUser, + listener: (context, state) async { + await runAppFlowy(); + }, + child: BlocBuilder( + builder: (context, state) { + final text = state.historicalUsers.isEmpty + ? LocaleKeys.letsGoButtonText.tr() + : LocaleKeys.signIn_continueAnonymousUser.tr(); + + final textWidget = FlowyText.medium( + text, + textAlign: TextAlign.center, + fontSize: 14, + ); + + return SizedBox( + width: 340, + height: 48, + child: FlowyButton( + isSelected: true, + text: textWidget, + radius: Corners.s6Border, + onTap: () { + if (state.historicalUsers.isNotEmpty) { + final bloc = context.read(); + final historicalUser = state.historicalUsers.first; + bloc.add( + HistoricalUserEvent.openHistoricalUser(historicalUser), + ); + } else { + onPressed(); + } + }, + ), + ); + }, + ), ), - radius: BorderRadius.circular(12), - mainAxisAlignment: MainAxisAlignment.center, - fontSize: FontSizes.s14, - fontFamily: GoogleFonts.poppins(fontWeight: FontWeight.w500).fontFamily, - padding: const EdgeInsets.symmetric(vertical: 14.0), - onPressed: onPressed, - fillColor: Theme.of(context).colorScheme.primary, - fontColor: Theme.of(context).colorScheme.onPrimary, - hoverColor: Theme.of(context).colorScheme.primaryContainer, ); } }