Skip to content

Commit 99f07fc

Browse files
committed
feat(content): add EditSourceState
- Implemented state management - Added EditSourceStatus enum - Defined state variables
1 parent 5a7aefe commit 99f07fc

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
part of 'edit_source_bloc.dart';
2+
3+
/// Represents the status of the edit source operation.
4+
enum EditSourceStatus {
5+
/// Initial state, before any data is loaded.
6+
initial,
7+
8+
/// Data is being loaded.
9+
loading,
10+
11+
/// An operation completed successfully.
12+
success,
13+
14+
/// An error occurred.
15+
failure,
16+
17+
/// The form is being submitted.
18+
submitting,
19+
}
20+
21+
/// The state for the [EditSourceBloc].
22+
final class EditSourceState extends Equatable {
23+
const EditSourceState({
24+
this.status = EditSourceStatus.initial,
25+
this.initialSource,
26+
this.name = '',
27+
this.description = '',
28+
this.url = '',
29+
this.sourceType,
30+
this.language = '',
31+
this.headquarters,
32+
this.countries = const [],
33+
this.errorMessage,
34+
});
35+
36+
final EditSourceStatus status;
37+
final Source? initialSource;
38+
final String name;
39+
final String description;
40+
final String url;
41+
final SourceType? sourceType;
42+
final String language;
43+
final Country? headquarters;
44+
final List<Country> countries;
45+
final String? errorMessage;
46+
47+
/// Returns true if the form is valid and can be submitted.
48+
bool get isFormValid => name.isNotEmpty;
49+
50+
EditSourceState copyWith({
51+
EditSourceStatus? status,
52+
Source? initialSource,
53+
String? name,
54+
String? description,
55+
String? url,
56+
ValueGetter<SourceType?>? sourceType,
57+
String? language,
58+
ValueGetter<Country?>? headquarters,
59+
List<Country>? countries,
60+
String? errorMessage,
61+
}) {
62+
return EditSourceState(
63+
status: status ?? this.status,
64+
initialSource: initialSource ?? this.initialSource,
65+
name: name ?? this.name,
66+
description: description ?? this.description,
67+
url: url ?? this.url,
68+
sourceType: sourceType != null ? sourceType() : this.sourceType,
69+
language: language ?? this.language,
70+
headquarters: headquarters != null ? headquarters() : this.headquarters,
71+
countries: countries ?? this.countries,
72+
errorMessage: errorMessage ?? this.errorMessage,
73+
);
74+
}
75+
76+
@override
77+
List<Object?> get props => [
78+
status,
79+
initialSource,
80+
name,
81+
description,
82+
url,
83+
sourceType,
84+
language,
85+
headquarters,
86+
countries,
87+
errorMessage,
88+
];
89+
}

0 commit comments

Comments
 (0)