Skip to content

Commit

Permalink
feat(app): add loading messages to login
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 7, 2024
1 parent f889934 commit cda7cdb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/integration_test/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
group('integration tests for the login page', () {
testWidgets('test loading state', (tester) async {
when(() => mockLoginCubit.state).thenReturn(
LoginState.loadingUserData(),
LoginState.loadingUserData(null),
);

await tester.pumpWidget(
Expand Down
2 changes: 2 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"auth_choose_lab": "Please select your data provider",
"auth_sign_in": "Get data",
"auth_success": "Successfully imported data",
"auth_loading_data": "Loading your data, please do not close the app...",
"auth_updating_data": "Checking for updates, please do not close the app...",

"drug_item_brand_names": "Brand names",

Expand Down
15 changes: 13 additions & 2 deletions app/lib/login/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class LoginCubit extends Cubit<LoginState> {
// signInAndLoadUserData authenticates a user with a Lab and fetches their
// genomic data from it's endpoint.
Future<void> signInAndLoadUserData(BuildContext context, Lab lab) async {
emit(LoginState.loadingUserData());
emit(LoginState.loadingUserData(null));

// authenticate
String? token;
Expand All @@ -46,11 +46,21 @@ class LoginCubit extends Cubit<LoginState> {
}

try {
final needNewDataLoad =
shouldFetchDiplotypes() || shouldUpdateGenotypeResults();
// get data
if (needNewDataLoad) {
// ignore: use_build_context_synchronously
emit(LoginState.loadingUserData(context.l10n.auth_loading_data));
}
await fetchAndSaveDiplotypesAndActiveDrugs(
token, lab.starAllelesUrl.toString(), activeDrugs);
await updateGenotypeResults();

if (!needNewDataLoad) {
// ignore: use_build_context_synchronously
emit(LoginState.loadingUserData(context.l10n.auth_updating_data));
}
await updateCachedDrugs();

// login + fetching of data successful
Expand Down Expand Up @@ -104,7 +114,8 @@ class LoginCubit extends Cubit<LoginState> {
@freezed
class LoginState with _$LoginState {
const factory LoginState.initial() = _InitialState;
const factory LoginState.loadingUserData() = _LoadingUserDataState;
const factory LoginState.loadingUserData(String? loadingMessage) =
_LoadingUserDataState;
const factory LoginState.loadedUserData() = _LoadedUserDataState;
const factory LoginState.error(String string) = _ErrorState;
}
16 changes: 14 additions & 2 deletions app/lib/login/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@ class LoginPage extends HookWidget {
child: state.when(
initial: () =>
_buildInitialScreen(context, dropdownValue),
loadingUserData: () => Padding(
loadingUserData: (loadingMessage) => Padding(
padding: EdgeInsets.all(PharMeTheme.largeSpace),
child: CircularProgressIndicator(),
child: Column(
children: [
CircularProgressIndicator(),
if (loadingMessage != null) ...[
SizedBox(height: PharMeTheme.largeSpace),
Text(
loadingMessage,
style: context.textTheme.titleLarge,
textAlign: TextAlign.center,
),
],
],
),
),
loadedUserData: () => _buildLoadedScreen(context),
error: (message) =>
Expand Down

0 comments on commit cda7cdb

Please sign in to comment.