diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index bc512f1..17869ee 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -62,35 +62,35 @@ Future bootstrap(app_config.AppConfig appConfig) async { HtDataClient appConfigClient; if (appConfig.environment == app_config.AppEnvironment.demo) { - headlinesClient = HtDataInMemoryClient( + headlinesClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, initialData: headlinesFixturesData.map(Headline.fromJson).toList(), ); - categoriesClient = HtDataInMemoryClient( + categoriesClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, initialData: categoriesFixturesData.map(Category.fromJson).toList(), ); - countriesClient = HtDataInMemoryClient( + countriesClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, initialData: countriesFixturesData.map(Country.fromJson).toList(), ); - sourcesClient = HtDataInMemoryClient( + sourcesClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, initialData: sourcesFixturesData.map(Source.fromJson).toList(), ); - userContentPreferencesClient = HtDataInMemoryClient( + userContentPreferencesClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, ); - userAppSettingsClient = HtDataInMemoryClient( + userAppSettingsClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, ); - appConfigClient = HtDataInMemoryClient( + appConfigClient = HtDataInMemory( toJson: (i) => i.toJson(), getId: (i) => i.id, initialData: [AppConfig.fromJson(appConfigFixtureData)], diff --git a/lib/settings/bloc/settings_bloc.dart b/lib/settings/bloc/settings_bloc.dart index de4f661..3066e60 100644 --- a/lib/settings/bloc/settings_bloc.dart +++ b/lib/settings/bloc/settings_bloc.dart @@ -60,12 +60,20 @@ class SettingsBloc extends Bloc { ) async { try { await _userAppSettingsRepository.update( - id: settingsToSave.id, // UserID is the ID of UserAppSettings + id: settingsToSave.id, item: settingsToSave, - userId: settingsToSave.id, // Pass userId for repository method + userId: settingsToSave.id, + ); + } on NotFoundException { + // If settings not found, create them + // needed speciically for teh demo mode + // that uses the ht data in memory impl + // as for the api impl, teh backend handle + // this use case. + await _userAppSettingsRepository.create( + item: settingsToSave, + userId: settingsToSave.id, ); - // State already updated optimistically, no need to emit success here - // unless we want a specific "save success" status. } on HtHttpException catch (e) { emit(state.copyWith(status: SettingsStatus.failure, error: e)); } catch (e) { diff --git a/pubspec.lock b/pubspec.lock index 79add15..ecd107c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -368,7 +368,7 @@ packages: description: path: "." ref: HEAD - resolved-ref: "82b6f31b8c23b740e9c473d6f40831b4f2cbd802" + resolved-ref: "3353842a1f1be1ab2563f2ba236daf49dd19a85e" url: "https://github.com/headlines-toolkit/ht-data-inmemory.git" source: git version: "0.0.0"