Skip to content

Commit 4cd8ac9

Browse files
committed
refactor(app): ensure immediate UI update after fixture injection
Refactors the `AppBloc`'s `_onAppUserChanged` handler to immediately call `_fetchAndSetUserData` after the `DemoDataInitializerService` successfully creates fixture data for a new user. This change guarantees that the UI receives the newly populated `UserAppSettings` and `UserContentPreferences` without delay, ensuring that components like the `SavedFiltersBar` are correctly displayed with pre-filled data upon the first launch for an anonymous user in the demo environment.
1 parent 72fc982 commit 4cd8ac9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ class AppBloc extends Bloc<AppEvent, AppState> {
350350
'[AppBloc] Demo mode: User-specific data initialized for '
351351
'user: ${newUser.id}.',
352352
);
353+
// After successful initialization, immediately re-fetch the user data.
354+
// This ensures that the newly created fixture data (settings and preferences)
355+
// is loaded into the AppState and propagated to the UI, making features
356+
// like the saved filters bar immediately visible.
357+
await _fetchAndSetUserData(newUser, emit);
353358
} catch (e, s) {
354359
_logger.severe(
355360
'[AppBloc] ERROR: Failed to initialize demo user data.',
@@ -408,9 +413,12 @@ class AppBloc extends Bloc<AppEvent, AppState> {
408413
}
409414
}
410415

411-
// After potential initialization and migration,
412-
// ensure user-specific data (settings and preferences) are loaded.
413-
await _fetchAndSetUserData(newUser, emit);
416+
// If not in demo mode, or if the demo initializer is not used,
417+
// perform the standard data fetch. In demo mode, this call is now
418+
// redundant as it's handled immediately after initialization.
419+
if (_environment != local_config.AppEnvironment.demo) {
420+
await _fetchAndSetUserData(newUser, emit);
421+
}
414422
} else {
415423
// If user logs out, clear user-specific data from state.
416424
emit(state.copyWith(settings: null, userContentPreferences: null));

lib/bootstrap.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,6 @@ Future<Widget> bootstrap(
469469
);
470470

471471
// Conditionally instantiate DemoDataInitializerService
472-
// This service is responsible for ensuring that essential user-specific data
473-
// (like UserAppSettings, UserContentPreferences)
474-
// exists in the data in-memory clients when a user is first encountered
475-
// in the demo environment.
476472
// In the demo environment, this service acts as a "fixture injector".
477473
// When a new user is encountered, it clones pre-defined fixture data
478474
// (settings and preferences, including saved filters) for that user,

0 commit comments

Comments
 (0)