Skip to content

Commit 43cc94c

Browse files
authored
Merge pull request #40 from headlines-toolkit/fix_settings_page_for_demo_mode
Fix settings page for demo mode
2 parents 9282bcf + 83bedcb commit 43cc94c

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

lib/bootstrap.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,35 @@ Future<void> bootstrap(app_config.AppConfig appConfig) async {
6262
HtDataClient<AppConfig> appConfigClient;
6363

6464
if (appConfig.environment == app_config.AppEnvironment.demo) {
65-
headlinesClient = HtDataInMemoryClient<Headline>(
65+
headlinesClient = HtDataInMemory<Headline>(
6666
toJson: (i) => i.toJson(),
6767
getId: (i) => i.id,
6868
initialData: headlinesFixturesData.map(Headline.fromJson).toList(),
6969
);
70-
categoriesClient = HtDataInMemoryClient<Category>(
70+
categoriesClient = HtDataInMemory<Category>(
7171
toJson: (i) => i.toJson(),
7272
getId: (i) => i.id,
7373
initialData: categoriesFixturesData.map(Category.fromJson).toList(),
7474
);
75-
countriesClient = HtDataInMemoryClient<Country>(
75+
countriesClient = HtDataInMemory<Country>(
7676
toJson: (i) => i.toJson(),
7777
getId: (i) => i.id,
7878
initialData: countriesFixturesData.map(Country.fromJson).toList(),
7979
);
80-
sourcesClient = HtDataInMemoryClient<Source>(
80+
sourcesClient = HtDataInMemory<Source>(
8181
toJson: (i) => i.toJson(),
8282
getId: (i) => i.id,
8383
initialData: sourcesFixturesData.map(Source.fromJson).toList(),
8484
);
85-
userContentPreferencesClient = HtDataInMemoryClient<UserContentPreferences>(
85+
userContentPreferencesClient = HtDataInMemory<UserContentPreferences>(
8686
toJson: (i) => i.toJson(),
8787
getId: (i) => i.id,
8888
);
89-
userAppSettingsClient = HtDataInMemoryClient<UserAppSettings>(
89+
userAppSettingsClient = HtDataInMemory<UserAppSettings>(
9090
toJson: (i) => i.toJson(),
9191
getId: (i) => i.id,
9292
);
93-
appConfigClient = HtDataInMemoryClient<AppConfig>(
93+
appConfigClient = HtDataInMemory<AppConfig>(
9494
toJson: (i) => i.toJson(),
9595
getId: (i) => i.id,
9696
initialData: [AppConfig.fromJson(appConfigFixtureData)],

lib/settings/bloc/settings_bloc.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
6060
) async {
6161
try {
6262
await _userAppSettingsRepository.update(
63-
id: settingsToSave.id, // UserID is the ID of UserAppSettings
63+
id: settingsToSave.id,
6464
item: settingsToSave,
65-
userId: settingsToSave.id, // Pass userId for repository method
65+
userId: settingsToSave.id,
66+
);
67+
} on NotFoundException {
68+
// If settings not found, create them
69+
// needed speciically for teh demo mode
70+
// that uses the ht data in memory impl
71+
// as for the api impl, teh backend handle
72+
// this use case.
73+
await _userAppSettingsRepository.create(
74+
item: settingsToSave,
75+
userId: settingsToSave.id,
6676
);
67-
// State already updated optimistically, no need to emit success here
68-
// unless we want a specific "save success" status.
6977
} on HtHttpException catch (e) {
7078
emit(state.copyWith(status: SettingsStatus.failure, error: e));
7179
} catch (e) {

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ packages:
368368
description:
369369
path: "."
370370
ref: HEAD
371-
resolved-ref: "82b6f31b8c23b740e9c473d6f40831b4f2cbd802"
371+
resolved-ref: "3353842a1f1be1ab2563f2ba236daf49dd19a85e"
372372
url: "https://github.com/headlines-toolkit/ht-data-inmemory.git"
373373
source: git
374374
version: "0.0.0"

0 commit comments

Comments
 (0)