11import 'package:bloc/bloc.dart' ;
22import 'package:equatable/equatable.dart' ;
33import 'package:ht_data_repository/ht_data_repository.dart' ;
4+ import 'package:ht_dashboard/shared/constants/pagination_constants.dart' ;
45import 'package:ht_shared/ht_shared.dart' ;
56
67part 'content_management_event.dart' ;
@@ -60,14 +61,17 @@ class ContentManagementBloc
6061 ) async {
6162 emit (state.copyWith (headlinesStatus: ContentManagementStatus .loading));
6263 try {
64+ final isPaginating = event.startAfterId != null ;
65+ final previousHeadlines = isPaginating ? state.headlines : < Headline > [];
66+ 6367 final paginatedHeadlines = await _headlinesRepository.readAll (
6468 startAfterId: event.startAfterId,
6569 limit: event.limit,
6670 );
6771 emit (
6872 state.copyWith (
6973 headlinesStatus: ContentManagementStatus .success,
70- headlines: paginatedHeadlines.items,
74+ headlines: [...previousHeadlines, ... paginatedHeadlines.items] ,
7175 headlinesCursor: paginatedHeadlines.cursor,
7276 headlinesHasMore: paginatedHeadlines.hasMore,
7377 ),
@@ -97,7 +101,9 @@ class ContentManagementBloc
97101 try {
98102 await _headlinesRepository.create (item: event.headline);
99103 // Reload headlines after creation
100- add (const LoadHeadlinesRequested ());
104+ add (
105+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
106+ );
101107 } on HtHttpException catch (e) {
102108 emit (
103109 state.copyWith (
@@ -123,7 +129,9 @@ class ContentManagementBloc
123129 try {
124130 await _headlinesRepository.update (id: event.id, item: event.headline);
125131 // Reload headlines after update
126- add (const LoadHeadlinesRequested ());
132+ add (
133+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
134+ );
127135 } on HtHttpException catch (e) {
128136 emit (
129137 state.copyWith (
@@ -149,7 +157,9 @@ class ContentManagementBloc
149157 try {
150158 await _headlinesRepository.delete (id: event.id);
151159 // Reload headlines after deletion
152- add (const LoadHeadlinesRequested ());
160+ add (
161+ const LoadHeadlinesRequested (limit: kDefaultRowsPerPage),
162+ );
153163 } on HtHttpException catch (e) {
154164 emit (
155165 state.copyWith (
@@ -173,14 +183,17 @@ class ContentManagementBloc
173183 ) async {
174184 emit (state.copyWith (categoriesStatus: ContentManagementStatus .loading));
175185 try {
186+ final isPaginating = event.startAfterId != null ;
187+ final previousCategories = isPaginating ? state.categories : < Category > [];
188+ 176189 final paginatedCategories = await _categoriesRepository.readAll (
177190 startAfterId: event.startAfterId,
178191 limit: event.limit,
179192 );
180193 emit (
181194 state.copyWith (
182195 categoriesStatus: ContentManagementStatus .success,
183- categories: paginatedCategories.items,
196+ categories: [...previousCategories, ... paginatedCategories.items] ,
184197 categoriesCursor: paginatedCategories.cursor,
185198 categoriesHasMore: paginatedCategories.hasMore,
186199 ),
@@ -210,7 +223,9 @@ class ContentManagementBloc
210223 try {
211224 await _categoriesRepository.create (item: event.category);
212225 // Reload categories after creation
213- add (const LoadCategoriesRequested ());
226+ add (
227+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
228+ );
214229 } on HtHttpException catch (e) {
215230 emit (
216231 state.copyWith (
@@ -236,7 +251,9 @@ class ContentManagementBloc
236251 try {
237252 await _categoriesRepository.update (id: event.id, item: event.category);
238253 // Reload categories after update
239- add (const LoadCategoriesRequested ());
254+ add (
255+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
256+ );
240257 } on HtHttpException catch (e) {
241258 emit (
242259 state.copyWith (
@@ -262,7 +279,9 @@ class ContentManagementBloc
262279 try {
263280 await _categoriesRepository.delete (id: event.id);
264281 // Reload categories after deletion
265- add (const LoadCategoriesRequested ());
282+ add (
283+ const LoadCategoriesRequested (limit: kDefaultRowsPerPage),
284+ );
266285 } on HtHttpException catch (e) {
267286 emit (
268287 state.copyWith (
@@ -286,14 +305,17 @@ class ContentManagementBloc
286305 ) async {
287306 emit (state.copyWith (sourcesStatus: ContentManagementStatus .loading));
288307 try {
308+ final isPaginating = event.startAfterId != null ;
309+ final previousSources = isPaginating ? state.sources : < Source > [];
310+ 289311 final paginatedSources = await _sourcesRepository.readAll (
290312 startAfterId: event.startAfterId,
291313 limit: event.limit,
292314 );
293315 emit (
294316 state.copyWith (
295317 sourcesStatus: ContentManagementStatus .success,
296- sources: paginatedSources.items,
318+ sources: [...previousSources, ... paginatedSources.items] ,
297319 sourcesCursor: paginatedSources.cursor,
298320 sourcesHasMore: paginatedSources.hasMore,
299321 ),
@@ -323,7 +345,9 @@ class ContentManagementBloc
323345 try {
324346 await _sourcesRepository.create (item: event.source);
325347 // Reload sources after creation
326- add (const LoadSourcesRequested ());
348+ add (
349+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
350+ );
327351 } on HtHttpException catch (e) {
328352 emit (
329353 state.copyWith (
@@ -349,7 +373,9 @@ class ContentManagementBloc
349373 try {
350374 await _sourcesRepository.update (id: event.id, item: event.source);
351375 // Reload sources after update
352- add (const LoadSourcesRequested ());
376+ add (
377+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
378+ );
353379 } on HtHttpException catch (e) {
354380 emit (
355381 state.copyWith (
@@ -375,7 +401,9 @@ class ContentManagementBloc
375401 try {
376402 await _sourcesRepository.delete (id: event.id);
377403 // Reload sources after deletion
378- add (const LoadSourcesRequested ());
404+ add (
405+ const LoadSourcesRequested (limit: kDefaultRowsPerPage),
406+ );
379407 } on HtHttpException catch (e) {
380408 emit (
381409 state.copyWith (
0 commit comments