@@ -30,15 +30,12 @@ class ContentManagementBloc
30
30
super (const ContentManagementState ()) {
31
31
on < ContentManagementTabChanged > (_onContentManagementTabChanged);
32
32
on < LoadHeadlinesRequested > (_onLoadHeadlinesRequested);
33
- on < HeadlineAdded > (_onHeadlineAdded);
34
33
on < HeadlineUpdated > (_onHeadlineUpdated);
35
34
on < DeleteHeadlineRequested > (_onDeleteHeadlineRequested);
36
35
on < LoadCategoriesRequested > (_onLoadCategoriesRequested);
37
- on < CategoryAdded > (_onCategoryAdded);
38
36
on < CategoryUpdated > (_onCategoryUpdated);
39
37
on < DeleteCategoryRequested > (_onDeleteCategoryRequested);
40
38
on < LoadSourcesRequested > (_onLoadSourcesRequested);
41
- on < SourceAdded > (_onSourceAdded);
42
39
on < SourceUpdated > (_onSourceUpdated);
43
40
on < DeleteSourceRequested > (_onOnDeleteSourceRequested);
44
41
}
@@ -92,31 +89,6 @@ class ContentManagementBloc
92
89
}
93
90
}
94
91
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
-
120
92
Future <void > _onDeleteHeadlineRequested (
121
93
DeleteHeadlineRequested event,
122
94
Emitter <ContentManagementState > emit,
@@ -144,6 +116,18 @@ class ContentManagementBloc
144
116
}
145
117
}
146
118
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
+
147
131
Future <void > _onLoadCategoriesRequested (
148
132
LoadCategoriesRequested event,
149
133
Emitter <ContentManagementState > emit,
@@ -182,33 +166,6 @@ class ContentManagementBloc
182
166
}
183
167
}
184
168
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
-
212
169
Future <void > _onDeleteCategoryRequested (
213
170
DeleteCategoryRequested event,
214
171
Emitter <ContentManagementState > emit,
@@ -236,6 +193,20 @@ class ContentManagementBloc
236
193
}
237
194
}
238
195
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
+
239
210
Future <void > _onLoadSourcesRequested (
240
211
LoadSourcesRequested event,
241
212
Emitter <ContentManagementState > emit,
@@ -274,28 +245,6 @@ class ContentManagementBloc
274
245
}
275
246
}
276
247
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
-
299
248
Future <void > _onOnDeleteSourceRequested (
300
249
DeleteSourceRequested event,
301
250
Emitter <ContentManagementState > emit,
@@ -322,4 +271,16 @@ class ContentManagementBloc
322
271
);
323
272
}
324
273
}
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
+ }
325
286
}
0 commit comments