@@ -30,15 +30,12 @@ class ContentManagementBloc
3030 super (const ContentManagementState ()) {
3131 on < ContentManagementTabChanged > (_onContentManagementTabChanged);
3232 on < LoadHeadlinesRequested > (_onLoadHeadlinesRequested);
33- on < HeadlineAdded > (_onHeadlineAdded);
3433 on < HeadlineUpdated > (_onHeadlineUpdated);
3534 on < DeleteHeadlineRequested > (_onDeleteHeadlineRequested);
3635 on < LoadCategoriesRequested > (_onLoadCategoriesRequested);
37- on < CategoryAdded > (_onCategoryAdded);
3836 on < CategoryUpdated > (_onCategoryUpdated);
3937 on < DeleteCategoryRequested > (_onDeleteCategoryRequested);
4038 on < LoadSourcesRequested > (_onLoadSourcesRequested);
41- on < SourceAdded > (_onSourceAdded);
4239 on < SourceUpdated > (_onSourceUpdated);
4340 on < DeleteSourceRequested > (_onOnDeleteSourceRequested);
4441 }
@@ -92,31 +89,6 @@ class ContentManagementBloc
9289 }
9390 }
9491
95- void _onHeadlineAdded (
96- HeadlineAdded event,
97- Emitter <ContentManagementState > emit,
98- ) {
99- final updatedHeadlines = [event.headline, ...state.headlines];
100- emit (
101- state.copyWith (
102- headlines: updatedHeadlines,
103- headlinesStatus: ContentManagementStatus .success,
104- ),
105- );
106- }
107-
108- void _onHeadlineUpdated (
109- HeadlineUpdated event,
110- Emitter <ContentManagementState > emit,
111- ) {
112- final updatedHeadlines = List <Headline >.from (state.headlines);
113- final index = updatedHeadlines.indexWhere ((h) => h.id == event.headline.id);
114- if (index != - 1 ) {
115- updatedHeadlines[index] = event.headline;
116- emit (state.copyWith (headlines: updatedHeadlines));
117- }
118- }
119-
12092 Future <void > _onDeleteHeadlineRequested (
12193 DeleteHeadlineRequested event,
12294 Emitter <ContentManagementState > emit,
@@ -144,6 +116,18 @@ class ContentManagementBloc
144116 }
145117 }
146118
119+ void _onHeadlineUpdated (
120+ HeadlineUpdated event,
121+ Emitter <ContentManagementState > emit,
122+ ) {
123+ final updatedHeadlines = List <Headline >.from (state.headlines);
124+ final index = updatedHeadlines.indexWhere ((h) => h.id == event.headline.id);
125+ if (index != - 1 ) {
126+ updatedHeadlines[index] = event.headline;
127+ emit (state.copyWith (headlines: updatedHeadlines));
128+ }
129+ }
130+
147131 Future <void > _onLoadCategoriesRequested (
148132 LoadCategoriesRequested event,
149133 Emitter <ContentManagementState > emit,
@@ -182,33 +166,6 @@ class ContentManagementBloc
182166 }
183167 }
184168
185- void _onCategoryAdded (
186- CategoryAdded event,
187- Emitter <ContentManagementState > emit,
188- ) {
189- final updatedCategories = [event.category, ...state.categories];
190- emit (
191- state.copyWith (
192- categories: updatedCategories,
193- categoriesStatus: ContentManagementStatus .success,
194- ),
195- );
196- }
197-
198- void _onCategoryUpdated (
199- CategoryUpdated event,
200- Emitter <ContentManagementState > emit,
201- ) {
202- final updatedCategories = List <Category >.from (state.categories);
203- final index = updatedCategories.indexWhere (
204- (c) => c.id == event.category.id,
205- );
206- if (index != - 1 ) {
207- updatedCategories[index] = event.category;
208- emit (state.copyWith (categories: updatedCategories));
209- }
210- }
211-
212169 Future <void > _onDeleteCategoryRequested (
213170 DeleteCategoryRequested event,
214171 Emitter <ContentManagementState > emit,
@@ -236,6 +193,20 @@ class ContentManagementBloc
236193 }
237194 }
238195
196+ void _onCategoryUpdated (
197+ CategoryUpdated event,
198+ Emitter <ContentManagementState > emit,
199+ ) {
200+ final updatedCategories = List <Category >.from (state.categories);
201+ final index = updatedCategories.indexWhere (
202+ (c) => c.id == event.category.id,
203+ );
204+ if (index != - 1 ) {
205+ updatedCategories[index] = event.category;
206+ emit (state.copyWith (categories: updatedCategories));
207+ }
208+ }
209+
239210 Future <void > _onLoadSourcesRequested (
240211 LoadSourcesRequested event,
241212 Emitter <ContentManagementState > emit,
@@ -274,28 +245,6 @@ class ContentManagementBloc
274245 }
275246 }
276247
277- void _onSourceAdded (SourceAdded event, Emitter <ContentManagementState > emit) {
278- final updatedSources = [event.source, ...state.sources];
279- emit (
280- state.copyWith (
281- sources: updatedSources,
282- sourcesStatus: ContentManagementStatus .success,
283- ),
284- );
285- }
286-
287- void _onSourceUpdated (
288- SourceUpdated event,
289- Emitter <ContentManagementState > emit,
290- ) {
291- final updatedSources = List <Source >.from (state.sources);
292- final index = updatedSources.indexWhere ((s) => s.id == event.source.id);
293- if (index != - 1 ) {
294- updatedSources[index] = event.source;
295- emit (state.copyWith (sources: updatedSources));
296- }
297- }
298-
299248 Future <void > _onOnDeleteSourceRequested (
300249 DeleteSourceRequested event,
301250 Emitter <ContentManagementState > emit,
@@ -322,4 +271,16 @@ class ContentManagementBloc
322271 );
323272 }
324273 }
274+
275+ void _onSourceUpdated (
276+ SourceUpdated event,
277+ Emitter <ContentManagementState > emit,
278+ ) {
279+ final updatedSources = List <Source >.from (state.sources);
280+ final index = updatedSources.indexWhere ((s) => s.id == event.source.id);
281+ if (index != - 1 ) {
282+ updatedSources[index] = event.source;
283+ emit (state.copyWith (sources: updatedSources));
284+ }
285+ }
325286}
0 commit comments