Skip to content

Commit 83bedcb

Browse files
committed
feat(settings): Create settings if not found
- Handles missing settings on save - Needed for demo mode
1 parent 497ed22 commit 83bedcb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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)