Skip to content

Commit d3eaf31

Browse files
committed
feat: introduces the necessary data layer components for the new dashboard feature.
It sets up HtDataClient and HtDataRepository for the DashboardSummary model, providing both in-memory (for demo mode) and API-based (for development/production) implementations. The new HtDataRepository<DashboardSummary> is now provided to the application's widget tree via RepositoryProvider, making it accessible for the upcoming DashboardBloc.
1 parent 86e3ac6 commit d3eaf31

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

lib/app/view/app.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class App extends StatelessWidget {
3030
required HtDataRepository<UserContentPreferences>
3131
htUserContentPreferencesRepository,
3232
required HtDataRepository<AppConfig> htAppConfigRepository,
33+
required HtDataRepository<DashboardSummary> htDashboardSummaryRepository,
3334
required HtKVStorageService kvStorageService,
3435
required AppEnvironment environment,
3536
super.key,
@@ -42,6 +43,7 @@ class App extends StatelessWidget {
4243
_htUserContentPreferencesRepository = htUserContentPreferencesRepository,
4344
_htAppConfigRepository = htAppConfigRepository,
4445
_kvStorageService = kvStorageService,
46+
_htDashboardSummaryRepository = htDashboardSummaryRepository,
4547
_environment = environment;
4648

4749
final HtAuthRepository _htAuthenticationRepository;
@@ -53,6 +55,7 @@ class App extends StatelessWidget {
5355
final HtDataRepository<UserContentPreferences>
5456
_htUserContentPreferencesRepository;
5557
final HtDataRepository<AppConfig> _htAppConfigRepository;
58+
final HtDataRepository<DashboardSummary> _htDashboardSummaryRepository;
5659
final HtKVStorageService _kvStorageService;
5760
final AppEnvironment _environment;
5861

@@ -68,6 +71,7 @@ class App extends StatelessWidget {
6871
RepositoryProvider.value(value: _htUserAppSettingsRepository),
6972
RepositoryProvider.value(value: _htUserContentPreferencesRepository),
7073
RepositoryProvider.value(value: _htAppConfigRepository),
74+
RepositoryProvider.value(value: _htDashboardSummaryRepository),
7175
RepositoryProvider.value(value: _kvStorageService),
7276
],
7377
child: MultiBlocProvider(

lib/bootstrap.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Future<Widget> bootstrap(
6161
HtDataClient<UserContentPreferences> userContentPreferencesClient;
6262
HtDataClient<UserAppSettings> userAppSettingsClient;
6363
HtDataClient<AppConfig> appConfigClient;
64+
HtDataClient<DashboardSummary> dashboardSummaryClient;
6465

6566
if (appConfig.environment == app_config.AppEnvironment.demo) {
6667
headlinesClient = HtDataInMemory<Headline>(
@@ -96,6 +97,13 @@ Future<Widget> bootstrap(
9697
getId: (i) => i.id,
9798
initialData: [AppConfig.fromJson(appConfigFixtureData)],
9899
);
100+
dashboardSummaryClient = HtDataInMemory<DashboardSummary>(
101+
toJson: (i) => i.toJson(),
102+
getId: (i) => i.id,
103+
initialData: [
104+
DashboardSummary.fromJson(dashboardSummaryFixtureData),
105+
],
106+
);
99107
} else if (appConfig.environment == app_config.AppEnvironment.development) {
100108
headlinesClient = HtDataApi<Headline>(
101109
httpClient: httpClient!,
@@ -139,6 +147,12 @@ Future<Widget> bootstrap(
139147
fromJson: AppConfig.fromJson,
140148
toJson: (config) => config.toJson(),
141149
);
150+
dashboardSummaryClient = HtDataApi<DashboardSummary>(
151+
httpClient: httpClient,
152+
modelName: 'dashboard_summary',
153+
fromJson: DashboardSummary.fromJson,
154+
toJson: (summary) => summary.toJson(),
155+
);
142156
} else {
143157
headlinesClient = HtDataApi<Headline>(
144158
httpClient: httpClient!,
@@ -182,6 +196,12 @@ Future<Widget> bootstrap(
182196
fromJson: AppConfig.fromJson,
183197
toJson: (config) => config.toJson(),
184198
);
199+
dashboardSummaryClient = HtDataApi<DashboardSummary>(
200+
httpClient: httpClient,
201+
modelName: 'dashboard_summary',
202+
fromJson: DashboardSummary.fromJson,
203+
toJson: (summary) => summary.toJson(),
204+
);
185205
}
186206

187207
final headlinesRepository = HtDataRepository<Headline>(
@@ -204,6 +224,9 @@ Future<Widget> bootstrap(
204224
final appConfigRepository = HtDataRepository<AppConfig>(
205225
dataClient: appConfigClient,
206226
);
227+
final dashboardSummaryRepository = HtDataRepository<DashboardSummary>(
228+
dataClient: dashboardSummaryClient,
229+
);
207230

208231
return App(
209232
htAuthenticationRepository: authenticationRepository,
@@ -214,6 +237,7 @@ Future<Widget> bootstrap(
214237
htUserAppSettingsRepository: userAppSettingsRepository,
215238
htUserContentPreferencesRepository: userContentPreferencesRepository,
216239
htAppConfigRepository: appConfigRepository,
240+
htDashboardSummaryRepository: dashboardSummaryRepository,
217241
kvStorageService: kvStorage,
218242
environment: environment,
219243
);

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ packages:
304304
description:
305305
path: "."
306306
ref: HEAD
307-
resolved-ref: "9e771623f5745113d346fd4bfdb1abccf7e75049"
307+
resolved-ref: f19d602153d67f3741905d5b3d07a7490fbda9d4
308308
url: "https://github.com/headlines-toolkit/ht-shared.git"
309309
source: git
310310
version: "0.0.0"

0 commit comments

Comments
 (0)