Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/content_management/bloc/create_source/create_source_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
on<CreateSourceNameChanged>(_onNameChanged);
on<CreateSourceDescriptionChanged>(_onDescriptionChanged);
on<CreateSourceUrlChanged>(_onUrlChanged);
on<CreateSourceLogoUrlChanged>(_onLogoUrlChanged);
on<CreateSourceTypeChanged>(_onSourceTypeChanged);
on<CreateSourceLanguageChanged>(_onLanguageChanged);
on<CreateSourceHeadquartersChanged>(_onHeadquartersChanged);
Expand Down Expand Up @@ -49,6 +50,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
emit(state.copyWith(url: event.url));
}

void _onLogoUrlChanged(
CreateSourceLogoUrlChanged event,
Emitter<CreateSourceState> emit,
) {
// Update state when the logo URL input changes.
emit(state.copyWith(logoUrl: event.logoUrl));
}

void _onSourceTypeChanged(
CreateSourceTypeChanged event,
Emitter<CreateSourceState> emit,
Expand Down Expand Up @@ -81,6 +90,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
final newSource = Source(
id: _uuid.v4(),
name: state.name,
logoUrl: state.logoUrl,
description: state.description,
url: state.url,
sourceType: state.sourceType!,
Expand All @@ -92,6 +102,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
);

await _sourcesRepository.create(item: newSource);

emit(
state.copyWith(
status: CreateSourceStatus.success,
Expand Down Expand Up @@ -121,6 +132,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
final newSource = Source(
id: _uuid.v4(),
name: state.name,
logoUrl: state.logoUrl,
description: state.description,
url: state.url,
sourceType: state.sourceType!,
Expand All @@ -132,6 +144,7 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
);

await _sourcesRepository.create(item: newSource);

emit(
state.copyWith(
status: CreateSourceStatus.success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ final class CreateSourceUrlChanged extends CreateSourceEvent {
List<Object?> get props => [url];
}

/// Event for when the source's logo URL is changed.
final class CreateSourceLogoUrlChanged extends CreateSourceEvent {
const CreateSourceLogoUrlChanged(this.logoUrl);
final String logoUrl;
@override
List<Object?> get props => [logoUrl];
}

/// Event for when the source's type is changed.
final class CreateSourceTypeChanged extends CreateSourceEvent {
const CreateSourceTypeChanged(this.sourceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class CreateSourceState extends Equatable {
this.name = '',
this.description = '',
this.url = '',
this.logoUrl = '',
this.sourceType,
this.language,
this.headquarters,
Expand All @@ -37,6 +38,7 @@ final class CreateSourceState extends Equatable {
final String name;
final String description;
final String url;
final String logoUrl;
final SourceType? sourceType;
final Language? language;
final Country? headquarters;
Expand All @@ -48,6 +50,7 @@ final class CreateSourceState extends Equatable {
name.isNotEmpty &&
description.isNotEmpty &&
url.isNotEmpty &&
logoUrl.isNotEmpty &&
sourceType != null &&
language != null &&
headquarters != null;
Expand All @@ -57,6 +60,7 @@ final class CreateSourceState extends Equatable {
String? name,
String? description,
String? url,
String? logoUrl,
ValueGetter<SourceType?>? sourceType,
ValueGetter<Language?>? language,
ValueGetter<Country?>? headquarters,
Expand All @@ -68,6 +72,7 @@ final class CreateSourceState extends Equatable {
name: name ?? this.name,
description: description ?? this.description,
url: url ?? this.url,
logoUrl: logoUrl ?? this.logoUrl,
sourceType: sourceType != null ? sourceType() : this.sourceType,
language: language != null ? language() : this.language,
headquarters: headquarters != null ? headquarters() : this.headquarters,
Expand All @@ -82,6 +87,7 @@ final class CreateSourceState extends Equatable {
name,
description,
url,
logoUrl,
sourceType,
language,
headquarters,
Expand Down
16 changes: 16 additions & 0 deletions lib/content_management/bloc/edit_source/edit_source_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
on<EditSourceNameChanged>(_onNameChanged);
on<EditSourceDescriptionChanged>(_onDescriptionChanged);
on<EditSourceUrlChanged>(_onUrlChanged);
on<EditSourceLogoUrlChanged>(_onLogoUrlChanged);
on<EditSourceTypeChanged>(_onSourceTypeChanged);
on<EditSourceLanguageChanged>(_onLanguageChanged);
on<EditSourceHeadquartersChanged>(_onHeadquartersChanged);
Expand All @@ -44,6 +45,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
name: source.name,
description: source.description,
url: source.url,
logoUrl: source.logoUrl,
sourceType: () => source.sourceType,
language: () => source.language,
headquarters: () => source.headquarters,
Expand Down Expand Up @@ -89,6 +91,16 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
emit(state.copyWith(url: event.url, status: EditSourceStatus.initial));
}

void _onLogoUrlChanged(
EditSourceLogoUrlChanged event,
Emitter<EditSourceState> emit,
) {
// Update state when the logo URL input changes.
emit(
state.copyWith(logoUrl: event.logoUrl, status: EditSourceStatus.initial),
);
}

void _onSourceTypeChanged(
EditSourceTypeChanged event,
Emitter<EditSourceState> emit,
Expand Down Expand Up @@ -135,6 +147,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
final originalSource = await _sourcesRepository.read(id: state.sourceId);
final updatedSource = originalSource.copyWith(
name: state.name,
logoUrl: state.logoUrl,
description: state.description,
url: state.url,
sourceType: state.sourceType,
Expand All @@ -148,6 +161,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
id: state.sourceId,
item: updatedSource,
);

emit(
state.copyWith(
status: EditSourceStatus.success,
Expand Down Expand Up @@ -176,6 +190,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
final originalSource = await _sourcesRepository.read(id: state.sourceId);
final updatedSource = originalSource.copyWith(
name: state.name,
logoUrl: state.logoUrl,
description: state.description,
url: state.url,
sourceType: state.sourceType,
Expand All @@ -189,6 +204,7 @@ class EditSourceBloc extends Bloc<EditSourceEvent, EditSourceState> {
id: state.sourceId,
item: updatedSource,
);

emit(
state.copyWith(
status: EditSourceStatus.success,
Expand Down
10 changes: 10 additions & 0 deletions lib/content_management/bloc/edit_source/edit_source_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ final class EditSourceUrlChanged extends EditSourceEvent {
List<Object?> get props => [url];
}

/// Event triggered when the source logo URL input changes.
final class EditSourceLogoUrlChanged extends EditSourceEvent {
const EditSourceLogoUrlChanged(this.logoUrl);

final String logoUrl;

@override
List<Object?> get props => [logoUrl];
}

/// Event triggered when the source type input changes.
final class EditSourceTypeChanged extends EditSourceEvent {
const EditSourceTypeChanged(this.sourceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class EditSourceState extends Equatable {
this.name = '',
this.description = '',
this.url = '',
this.logoUrl = '',
this.sourceType,
this.language,
this.headquarters,
Expand All @@ -38,6 +39,7 @@ final class EditSourceState extends Equatable {
final String name;
final String description;
final String url;
final String logoUrl;
final SourceType? sourceType;
final Language? language;
final Country? headquarters;
Expand All @@ -50,6 +52,7 @@ final class EditSourceState extends Equatable {
name.isNotEmpty &&
description.isNotEmpty &&
url.isNotEmpty &&
logoUrl.isNotEmpty &&
sourceType != null &&
language != null &&
headquarters != null;
Expand All @@ -60,6 +63,7 @@ final class EditSourceState extends Equatable {
String? name,
String? description,
String? url,
String? logoUrl,
ValueGetter<SourceType?>? sourceType,
ValueGetter<Language?>? language,
ValueGetter<Country?>? headquarters,
Expand All @@ -72,6 +76,7 @@ final class EditSourceState extends Equatable {
name: name ?? this.name,
description: description ?? this.description,
url: url ?? this.url,
logoUrl: logoUrl ?? this.logoUrl,
sourceType: sourceType != null ? sourceType() : this.sourceType,
language: language != null ? language() : this.language,
headquarters: headquarters != null ? headquarters() : this.headquarters,
Expand All @@ -87,6 +92,7 @@ final class EditSourceState extends Equatable {
name,
description,
url,
logoUrl,
sourceType,
language,
headquarters,
Expand Down
14 changes: 14 additions & 0 deletions lib/content_management/view/create_source_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
late final TextEditingController _nameController;
late final TextEditingController _descriptionController;
late final TextEditingController _urlController;
late final TextEditingController _logoUrlController;

@override
void initState() {
Expand All @@ -47,13 +48,15 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
_nameController = TextEditingController(text: state.name);
_descriptionController = TextEditingController(text: state.description);
_urlController = TextEditingController(text: state.url);
_logoUrlController = TextEditingController(text: state.logoUrl);
}

@override
void dispose() {
_nameController.dispose();
_descriptionController.dispose();
_urlController.dispose();
_logoUrlController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -211,6 +214,17 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
.add(CreateSourceUrlChanged(value)),
),
const SizedBox(height: AppSpacing.lg),
TextFormField(
controller: _logoUrlController,
decoration: InputDecoration(
labelText: l10n.logoUrl,
border: const OutlineInputBorder(),
),
onChanged: (value) => context
.read<CreateSourceBloc>()
.add(CreateSourceLogoUrlChanged(value)),
),
const SizedBox(height: AppSpacing.lg),
SearchableSelectionInput<Language>(
label: l10n.language,
selectedItems: state.language != null
Expand Down
15 changes: 15 additions & 0 deletions lib/content_management/view/edit_source_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ class _EditSourceViewState extends State<_EditSourceView> {
late final TextEditingController _nameController;
late final TextEditingController _descriptionController;
late final TextEditingController _urlController;
late final TextEditingController _logoUrlController;

@override
void initState() {
super.initState();
_nameController = TextEditingController();
_descriptionController = TextEditingController();
_urlController = TextEditingController();
_logoUrlController = TextEditingController();
}

@override
void dispose() {
_nameController.dispose();
_descriptionController.dispose();
_urlController.dispose();
_logoUrlController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -140,6 +143,7 @@ class _EditSourceViewState extends State<_EditSourceView> {
_nameController.text = state.name;
_descriptionController.text = state.description;
_urlController.text = state.url;
_logoUrlController.text = state.logoUrl;
}
},
builder: (context, state) {
Expand Down Expand Up @@ -201,6 +205,17 @@ class _EditSourceViewState extends State<_EditSourceView> {
),
),
const SizedBox(height: AppSpacing.lg),
TextFormField(
controller: _logoUrlController,
decoration: InputDecoration(
labelText: l10n.logoUrl,
border: const OutlineInputBorder(),
),
onChanged: (value) => context.read<EditSourceBloc>().add(
EditSourceLogoUrlChanged(value),
),
),
const SizedBox(height: AppSpacing.lg),
SearchableSelectionInput<Language>(
label: l10n.language,
selectedItems: state.language != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class _FilterDialogState extends State<FilterDialog> {
name: '',
description: '',
url: '',
logoUrl: '',
sourceType: SourceType.other,
language: Language(
id: '',
Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,12 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Do you want to publish this ad or save it as a draft?'**
String get saveAdMessage;

/// Label for the source logo URL input field
///
/// In en, this message translates to:
/// **'Logo URL'**
String get logoUrl;
}

class _AppLocalizationsDelegate
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1512,4 +1512,7 @@ class AppLocalizationsAr extends AppLocalizations {

@override
String get saveAdMessage => 'هل تريد نشر هذا الإعلان أم حفظه كمسودة؟';

@override
String get logoUrl => 'رابط الشعار';
}
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1518,4 +1518,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get saveAdMessage =>
'Do you want to publish this ad or save it as a draft?';

@override
String get logoUrl => 'Logo URL';
}
4 changes: 4 additions & 0 deletions lib/l10n/arb/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1919,5 +1919,9 @@
"saveAdMessage": "هل تريد نشر هذا الإعلان أم حفظه كمسودة؟",
"@saveAdMessage": {
"description": "رسالة مربع الحوار الذي يطلب حفظ إعلان"
},
"logoUrl": "رابط الشعار",
"@logoUrl": {
"description": "تسمية حقل إدخال رابط شعار المصدر"
}
}
4 changes: 4 additions & 0 deletions lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1915,5 +1915,9 @@
"saveAdMessage": "Do you want to publish this ad or save it as a draft?",
"@saveAdMessage": {
"description": "Message for the dialog asking to save an ad"
},
"logoUrl": "Logo URL",
"@logoUrl": {
"description": "Label for the source logo URL input field"
}
}
Loading
Loading