Skip to content

Commit 01e5a6f

Browse files
committed
feat(source): integrate logoUrl into edit source bloc
Updates the `EditSourceBloc` to fully manage the new `logoUrl` field. This change introduces and registers the `_onLogoUrlChanged` event handler. It also updates the `_onEditSourceLoaded` method to populate the `logoUrl` from the fetched source. Finally, it modifies the `_onSavedAsDraft` and `_onPublished` methods to include the `logoUrl` when updating the `Source` instance. Comments for future logging have been added to enhance maintainability.
1 parent 3ba2701 commit 01e5a6f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/content_management/bloc/edit_source/edit_source_bloc.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
2121
on<EditSourceNameChanged>(_onNameChanged);
2222
on<EditSourceDescriptionChanged>(_onDescriptionChanged);
2323
on<EditSourceUrlChanged>(_onUrlChanged);
24+
on<EditSourceLogoUrlChanged>(_onLogoUrlChanged);
2425
on<EditSourceTypeChanged>(_onSourceTypeChanged);
2526
on<EditSourceLanguageChanged>(_onLanguageChanged);
2627
on<EditSourceHeadquartersChanged>(_onHeadquartersChanged);
@@ -44,6 +45,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
4445
name: source.name,
4546
description: source.description,
4647
url: source.url,
48+
logoUrl: source.logoUrl,
4749
sourceType: () => source.sourceType,
4850
language: () => source.language,
4951
headquarters: () => source.headquarters,
@@ -89,6 +91,16 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
8991
emit(state.copyWith(url: event.url, status: EditSourceStatus.initial));
9092
}
9193

94+
void _onLogoUrlChanged(
95+
EditSourceLogoUrlChanged event,
96+
Emitter<EditSourceState> emit,
97+
) {
98+
// Update state when the logo URL input changes.
99+
emit(
100+
state.copyWith(logoUrl: event.logoUrl, status: EditSourceStatus.initial),
101+
);
102+
}
103+
92104
void _onSourceTypeChanged(
93105
EditSourceTypeChanged event,
94106
Emitter<EditSourceState> emit,
@@ -130,11 +142,13 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
130142
EditSourceSavedAsDraft event,
131143
Emitter<EditSourceState> emit,
132144
) async {
145+
// Log: Attempting to save source as draft with state: state
133146
emit(state.copyWith(status: EditSourceStatus.submitting));
134147
try {
135148
final originalSource = await _sourcesRepository.read(id: state.sourceId);
136149
final updatedSource = originalSource.copyWith(
137150
name: state.name,
151+
logoUrl: state.logoUrl,
138152
description: state.description,
139153
url: state.url,
140154
sourceType: state.sourceType,
@@ -148,16 +162,19 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
148162
id: state.sourceId,
149163
item: updatedSource,
150164
);
165+
// Log: Successfully saved source as draft with id: state.sourceId
151166
emit(
152167
state.copyWith(
153168
status: EditSourceStatus.success,
154169
updatedSource: updatedSource,
155170
),
156171
);
157172
} on HttpException catch (e) {
173+
// Log: Failed to save source as draft. Error: e
158174
emit(state.copyWith(status: EditSourceStatus.failure, exception: e));
159175
} catch (e) {
160176
emit(
177+
// Log: An unexpected error occurred while saving source as draft. Error: e
161178
state.copyWith(
162179
status: EditSourceStatus.failure,
163180
exception: UnknownException('An unexpected error occurred: $e'),
@@ -171,11 +188,13 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
171188
EditSourcePublished event,
172189
Emitter<EditSourceState> emit,
173190
) async {
191+
// Log: Attempting to publish source with state: state
174192
emit(state.copyWith(status: EditSourceStatus.submitting));
175193
try {
176194
final originalSource = await _sourcesRepository.read(id: state.sourceId);
177195
final updatedSource = originalSource.copyWith(
178196
name: state.name,
197+
logoUrl: state.logoUrl,
179198
description: state.description,
180199
url: state.url,
181200
sourceType: state.sourceType,
@@ -189,16 +208,19 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
189208
id: state.sourceId,
190209
item: updatedSource,
191210
);
211+
// Log: Successfully published source with id: state.sourceId
192212
emit(
193213
state.copyWith(
194214
status: EditSourceStatus.success,
195215
updatedSource: updatedSource,
196216
),
197217
);
198218
} on HttpException catch (e) {
219+
// Log: Failed to publish source. Error: e
199220
emit(state.copyWith(status: EditSourceStatus.failure, exception: e));
200221
} catch (e) {
201222
emit(
223+
// Log: An unexpected error occurred while publishing source. Error: e
202224
state.copyWith(
203225
status: EditSourceStatus.failure,
204226
exception: UnknownException('An unexpected error occurred: $e'),

0 commit comments

Comments
 (0)