1
1
import 'package:bloc/bloc.dart' ;
2
2
import 'package:equatable/equatable.dart' ;
3
3
import 'package:ht_data_repository/ht_data_repository.dart' ;
4
+ import 'package:ht_dashboard/shared/constants/pagination_constants.dart' ;
4
5
import 'package:ht_shared/ht_shared.dart' ;
5
6
6
7
part 'content_management_event.dart' ;
@@ -60,14 +61,17 @@ class ContentManagementBloc
60
61
) async {
61
62
emit (state.copyWith (headlinesStatus: ContentManagementStatus .loading));
62
63
try {
64
+ final isPaginating = event.startAfterId != null ;
65
+ final previousHeadlines = isPaginating ? state.headlines : < Headline > [];
66
+
63
67
final paginatedHeadlines = await _headlinesRepository.readAll (
64
68
startAfterId: event.startAfterId,
65
69
limit: event.limit,
66
70
);
67
71
emit (
68
72
state.copyWith (
69
73
headlinesStatus: ContentManagementStatus .success,
70
- headlines: paginatedHeadlines.items,
74
+ headlines: [...previousHeadlines, ... paginatedHeadlines.items] ,
71
75
headlinesCursor: paginatedHeadlines.cursor,
72
76
headlinesHasMore: paginatedHeadlines.hasMore,
73
77
),
@@ -97,7 +101,9 @@ class ContentManagementBloc
97
101
try {
98
102
await _headlinesRepository.create (item: event.headline);
99
103
// Reload headlines after creation
100
- add (const LoadHeadlinesRequested ());
104
+ add (
105
+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
106
+ );
101
107
} on HtHttpException catch (e) {
102
108
emit (
103
109
state.copyWith (
@@ -123,7 +129,9 @@ class ContentManagementBloc
123
129
try {
124
130
await _headlinesRepository.update (id: event.id, item: event.headline);
125
131
// Reload headlines after update
126
- add (const LoadHeadlinesRequested ());
132
+ add (
133
+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
134
+ );
127
135
} on HtHttpException catch (e) {
128
136
emit (
129
137
state.copyWith (
@@ -149,7 +157,9 @@ class ContentManagementBloc
149
157
try {
150
158
await _headlinesRepository.delete (id: event.id);
151
159
// Reload headlines after deletion
152
- add (const LoadHeadlinesRequested ());
160
+ add (
161
+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
162
+ );
153
163
} on HtHttpException catch (e) {
154
164
emit (
155
165
state.copyWith (
@@ -173,14 +183,17 @@ class ContentManagementBloc
173
183
) async {
174
184
emit (state.copyWith (categoriesStatus: ContentManagementStatus .loading));
175
185
try {
186
+ final isPaginating = event.startAfterId != null ;
187
+ final previousCategories = isPaginating ? state.categories : < Category > [];
188
+
176
189
final paginatedCategories = await _categoriesRepository.readAll (
177
190
startAfterId: event.startAfterId,
178
191
limit: event.limit,
179
192
);
180
193
emit (
181
194
state.copyWith (
182
195
categoriesStatus: ContentManagementStatus .success,
183
- categories: paginatedCategories.items,
196
+ categories: [...previousCategories, ... paginatedCategories.items] ,
184
197
categoriesCursor: paginatedCategories.cursor,
185
198
categoriesHasMore: paginatedCategories.hasMore,
186
199
),
@@ -210,7 +223,9 @@ class ContentManagementBloc
210
223
try {
211
224
await _categoriesRepository.create (item: event.category);
212
225
// Reload categories after creation
213
- add (const LoadCategoriesRequested ());
226
+ add (
227
+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
228
+ );
214
229
} on HtHttpException catch (e) {
215
230
emit (
216
231
state.copyWith (
@@ -236,7 +251,9 @@ class ContentManagementBloc
236
251
try {
237
252
await _categoriesRepository.update (id: event.id, item: event.category);
238
253
// Reload categories after update
239
- add (const LoadCategoriesRequested ());
254
+ add (
255
+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
256
+ );
240
257
} on HtHttpException catch (e) {
241
258
emit (
242
259
state.copyWith (
@@ -262,7 +279,9 @@ class ContentManagementBloc
262
279
try {
263
280
await _categoriesRepository.delete (id: event.id);
264
281
// Reload categories after deletion
265
- add (const LoadCategoriesRequested ());
282
+ add (
283
+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
284
+ );
266
285
} on HtHttpException catch (e) {
267
286
emit (
268
287
state.copyWith (
@@ -286,14 +305,17 @@ class ContentManagementBloc
286
305
) async {
287
306
emit (state.copyWith (sourcesStatus: ContentManagementStatus .loading));
288
307
try {
308
+ final isPaginating = event.startAfterId != null ;
309
+ final previousSources = isPaginating ? state.sources : < Source > [];
310
+
289
311
final paginatedSources = await _sourcesRepository.readAll (
290
312
startAfterId: event.startAfterId,
291
313
limit: event.limit,
292
314
);
293
315
emit (
294
316
state.copyWith (
295
317
sourcesStatus: ContentManagementStatus .success,
296
- sources: paginatedSources.items,
318
+ sources: [...previousSources, ... paginatedSources.items] ,
297
319
sourcesCursor: paginatedSources.cursor,
298
320
sourcesHasMore: paginatedSources.hasMore,
299
321
),
@@ -323,7 +345,9 @@ class ContentManagementBloc
323
345
try {
324
346
await _sourcesRepository.create (item: event.source);
325
347
// Reload sources after creation
326
- add (const LoadSourcesRequested ());
348
+ add (
349
+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
350
+ );
327
351
} on HtHttpException catch (e) {
328
352
emit (
329
353
state.copyWith (
@@ -349,7 +373,9 @@ class ContentManagementBloc
349
373
try {
350
374
await _sourcesRepository.update (id: event.id, item: event.source);
351
375
// Reload sources after update
352
- add (const LoadSourcesRequested ());
376
+ add (
377
+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
378
+ );
353
379
} on HtHttpException catch (e) {
354
380
emit (
355
381
state.copyWith (
@@ -375,7 +401,9 @@ class ContentManagementBloc
375
401
try {
376
402
await _sourcesRepository.delete (id: event.id);
377
403
// Reload sources after deletion
378
- add (const LoadSourcesRequested ());
404
+ add (
405
+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
406
+ );
379
407
} on HtHttpException catch (e) {
380
408
emit (
381
409
state.copyWith (
0 commit comments