Skip to content

Commit b231dd8

Browse files
committed
feat(content): add EditHeadlineState
- Implemented state management - Added status enum - Defined form validation
1 parent 6caa1d2 commit b231dd8

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
part of 'edit_headline_bloc.dart';
2+
3+
/// Represents the status of the edit headline operation.
4+
enum EditHeadlineStatus {
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 [EditHeadlineBloc].
22+
final class EditHeadlineState extends Equatable {
23+
const EditHeadlineState({
24+
this.status = EditHeadlineStatus.initial,
25+
this.initialHeadline,
26+
this.title = '',
27+
this.description = '',
28+
this.url = '',
29+
this.imageUrl = '',
30+
this.source,
31+
this.category,
32+
this.sources = const [],
33+
this.categories = const [],
34+
this.errorMessage,
35+
});
36+
37+
final EditHeadlineStatus status;
38+
final Headline? initialHeadline;
39+
final String title;
40+
final String description;
41+
final String url;
42+
final String imageUrl;
43+
final Source? source;
44+
final Category? category;
45+
final List<Source> sources;
46+
final List<Category> categories;
47+
final String? errorMessage;
48+
49+
/// Returns true if the form is valid and can be submitted.
50+
bool get isFormValid => title.isNotEmpty;
51+
52+
EditHeadlineState copyWith({
53+
EditHeadlineStatus? status,
54+
Headline? initialHeadline,
55+
String? title,
56+
String? description,
57+
String? url,
58+
String? imageUrl,
59+
ValueGetter<Source?>? source,
60+
ValueGetter<Category?>? category,
61+
List<Source>? sources,
62+
List<Category>? categories,
63+
String? errorMessage,
64+
}) {
65+
return EditHeadlineState(
66+
status: status ?? this.status,
67+
initialHeadline: initialHeadline ?? this.initialHeadline,
68+
title: title ?? this.title,
69+
description: description ?? this.description,
70+
url: url ?? this.url,
71+
imageUrl: imageUrl ?? this.imageUrl,
72+
source: source != null ? source() : this.source,
73+
category: category != null ? category() : this.category,
74+
sources: sources ?? this.sources,
75+
categories: categories ?? this.categories,
76+
errorMessage: errorMessage ?? this.errorMessage,
77+
);
78+
}
79+
80+
@override
81+
List<Object?> get props => [
82+
status,
83+
initialHeadline,
84+
title,
85+
description,
86+
url,
87+
imageUrl,
88+
source,
89+
category,
90+
sources,
91+
categories,
92+
errorMessage,
93+
];
94+
}

0 commit comments

Comments
 (0)