Skip to content

Commit 39e0f96

Browse files
committed
feat(source): integrate logoUrl into create source bloc
Updates the `CreateSourceBloc` to fully manage the new `logoUrl` field. This change introduces a new event handler `_onLogoUrlChanged` to update the state with the logo URL from the UI. It also registers this handler and modifies the `_onSavedAsDraft` and `_onPublished` methods to include the `logoUrl` when creating a new `Source` instance, resolving the compilation errors. Comments for future logging have been added to enhance maintainability.
1 parent a6fee37 commit 39e0f96

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/content_management/bloc/create_source/create_source_bloc.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
1818
on<CreateSourceNameChanged>(_onNameChanged);
1919
on<CreateSourceDescriptionChanged>(_onDescriptionChanged);
2020
on<CreateSourceUrlChanged>(_onUrlChanged);
21+
on<CreateSourceLogoUrlChanged>(_onLogoUrlChanged);
2122
on<CreateSourceTypeChanged>(_onSourceTypeChanged);
2223
on<CreateSourceLanguageChanged>(_onLanguageChanged);
2324
on<CreateSourceHeadquartersChanged>(_onHeadquartersChanged);
@@ -49,6 +50,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
4950
emit(state.copyWith(url: event.url));
5051
}
5152

53+
void _onLogoUrlChanged(
54+
CreateSourceLogoUrlChanged event,
55+
Emitter<CreateSourceState> emit,
56+
) {
57+
// Update state when the logo URL input changes.
58+
emit(state.copyWith(logoUrl: event.logoUrl));
59+
}
60+
5261
void _onSourceTypeChanged(
5362
CreateSourceTypeChanged event,
5463
Emitter<CreateSourceState> emit,
@@ -75,12 +84,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
7584
CreateSourceSavedAsDraft event,
7685
Emitter<CreateSourceState> emit,
7786
) async {
87+
// Log: Attempting to save source as draft with state: state
7888
emit(state.copyWith(status: CreateSourceStatus.submitting));
7989
try {
8090
final now = DateTime.now();
8191
final newSource = Source(
8292
id: _uuid.v4(),
8393
name: state.name,
94+
logoUrl: state.logoUrl,
8495
description: state.description,
8596
url: state.url,
8697
sourceType: state.sourceType!,
@@ -92,16 +103,19 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
92103
);
93104

94105
await _sourcesRepository.create(item: newSource);
106+
// Log: Successfully saved source as draft with id: newSource.id
95107
emit(
96108
state.copyWith(
97109
status: CreateSourceStatus.success,
98110
createdSource: newSource,
99111
),
100112
);
101113
} on HttpException catch (e) {
114+
// Log: Failed to save source as draft. Error: e
102115
emit(state.copyWith(status: CreateSourceStatus.failure, exception: e));
103116
} catch (e) {
104117
emit(
118+
// Log: An unexpected error occurred while saving source as draft. Error: e
105119
state.copyWith(
106120
status: CreateSourceStatus.failure,
107121
exception: UnknownException('An unexpected error occurred: $e'),
@@ -115,12 +129,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
115129
CreateSourcePublished event,
116130
Emitter<CreateSourceState> emit,
117131
) async {
132+
// Log: Attempting to publish source with state: state
118133
emit(state.copyWith(status: CreateSourceStatus.submitting));
119134
try {
120135
final now = DateTime.now();
121136
final newSource = Source(
122137
id: _uuid.v4(),
123138
name: state.name,
139+
logoUrl: state.logoUrl,
124140
description: state.description,
125141
url: state.url,
126142
sourceType: state.sourceType!,
@@ -132,16 +148,19 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
132148
);
133149

134150
await _sourcesRepository.create(item: newSource);
151+
// Log: Successfully published source with id: newSource.id
135152
emit(
136153
state.copyWith(
137154
status: CreateSourceStatus.success,
138155
createdSource: newSource,
139156
),
140157
);
141158
} on HttpException catch (e) {
159+
// Log: Failed to publish source. Error: e
142160
emit(state.copyWith(status: CreateSourceStatus.failure, exception: e));
143161
} catch (e) {
144162
emit(
163+
// Log: An unexpected error occurred while publishing source. Error: e
145164
state.copyWith(
146165
status: CreateSourceStatus.failure,
147166
exception: UnknownException('An unexpected error occurred: $e'),

0 commit comments

Comments
 (0)