@@ -42,19 +42,28 @@ class ContentManagementBloc
4242 _headlineUpdateSubscription = _headlinesRepository.entityUpdated
4343 .where ((type) => type == Headline )
4444 .listen ((_) {
45- add (const LoadHeadlinesRequested (limit: kDefaultRowsPerPage));
45+ add (const LoadHeadlinesRequested (
46+ limit: kDefaultRowsPerPage,
47+ forceRefresh: true ,
48+ ));
4649 });
4750
4851 _topicUpdateSubscription = _topicsRepository.entityUpdated
4952 .where ((type) => type == Topic )
5053 .listen ((_) {
51- add (const LoadTopicsRequested (limit: kDefaultRowsPerPage));
54+ add (const LoadTopicsRequested (
55+ limit: kDefaultRowsPerPage,
56+ forceRefresh: true ,
57+ ));
5258 });
5359
5460 _sourceUpdateSubscription = _sourcesRepository.entityUpdated
5561 .where ((type) => type == Source )
5662 .listen ((_) {
57- add (const LoadSourcesRequested (limit: kDefaultRowsPerPage));
63+ add (const LoadSourcesRequested (
64+ limit: kDefaultRowsPerPage,
65+ forceRefresh: true ,
66+ ));
5867 });
5968 }
6069
@@ -85,6 +94,15 @@ class ContentManagementBloc
8594 LoadHeadlinesRequested event,
8695 Emitter <ContentManagementState > emit,
8796 ) async {
97+ // If headlines are already loaded and it's not a pagination request,
98+ // do not re-fetch. This prevents redundant API calls on tab changes.
99+ if (state.headlinesStatus == ContentManagementStatus .success &&
100+ state.headlines.isNotEmpty &&
101+ event.startAfterId == null &&
102+ ! event.forceRefresh) {
103+ return ;
104+ }
105+
88106 emit (state.copyWith (headlinesStatus: ContentManagementStatus .loading));
89107 try {
90108 final isPaginating = event.startAfterId != null ;
@@ -166,6 +184,15 @@ class ContentManagementBloc
166184 LoadTopicsRequested event,
167185 Emitter <ContentManagementState > emit,
168186 ) async {
187+ // If topics are already loaded and it's not a pagination request,
188+ // do not re-fetch. This prevents redundant API calls on tab changes.
189+ if (state.topicsStatus == ContentManagementStatus .success &&
190+ state.topics.isNotEmpty &&
191+ event.startAfterId == null &&
192+ ! event.forceRefresh) {
193+ return ;
194+ }
195+
169196 emit (state.copyWith (topicsStatus: ContentManagementStatus .loading));
170197 try {
171198 final isPaginating = event.startAfterId != null ;
@@ -247,6 +274,15 @@ class ContentManagementBloc
247274 LoadSourcesRequested event,
248275 Emitter <ContentManagementState > emit,
249276 ) async {
277+ // If sources are already loaded and it's not a pagination request,
278+ // do not re-fetch. This prevents redundant API calls on tab changes.
279+ if (state.sourcesStatus == ContentManagementStatus .success &&
280+ state.sources.isNotEmpty &&
281+ event.startAfterId == null &&
282+ ! event.forceRefresh) {
283+ return ;
284+ }
285+
250286 emit (state.copyWith (sourcesStatus: ContentManagementStatus .loading));
251287 try {
252288 final isPaginating = event.startAfterId != null ;
0 commit comments