Skip to content

Commit 320fbed

Browse files
authored
Merge pull request #46 from flutter-news-app-full-source-code/content-management-ui-enhancement
Content management UI enhancement
2 parents 3c7e8d1 + d34651f commit 320fbed

16 files changed

+222
-552
lines changed

lib/content_management/bloc/create_headline/create_headline_bloc.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class CreateHeadlineBloc
3535
on<CreateHeadlineCountryChanged>(_onCountryChanged);
3636
on<CreateHeadlineStatusChanged>(_onStatusChanged);
3737
on<CreateHeadlineSubmitted>(_onSubmitted);
38-
on<CreateHeadlineCountrySearchChanged>(
39-
_onCountrySearchChanged,
40-
transformer: droppable(),
41-
);
4238
on<CreateHeadlineLoadMoreCountriesRequested>(_onLoadMoreCountriesRequested);
4339
}
4440

@@ -195,37 +191,6 @@ class CreateHeadlineBloc
195191
}
196192
}
197193

198-
Future<void> _onCountrySearchChanged(
199-
CreateHeadlineCountrySearchChanged event,
200-
Emitter<CreateHeadlineState> emit,
201-
) async {
202-
await Future<void>.delayed(_searchDebounceDuration);
203-
emit(state.copyWith(countrySearchTerm: event.searchTerm));
204-
try {
205-
final countriesResponse = await _countriesRepository.readAll(
206-
filter: event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null,
207-
sort: [const SortOption('name', SortOrder.asc)],
208-
);
209-
210-
emit(
211-
state.copyWith(
212-
countries: countriesResponse.items,
213-
countriesCursor: countriesResponse.cursor,
214-
countriesHasMore: countriesResponse.hasMore,
215-
),
216-
);
217-
} on HttpException catch (e) {
218-
emit(state.copyWith(status: CreateHeadlineStatus.failure, exception: e));
219-
} catch (e) {
220-
emit(
221-
state.copyWith(
222-
status: CreateHeadlineStatus.failure,
223-
exception: UnknownException('An unexpected error occurred: $e'),
224-
),
225-
);
226-
}
227-
}
228-
229194
Future<void> _onLoadMoreCountriesRequested(
230195
CreateHeadlineLoadMoreCountriesRequested event,
231196
Emitter<CreateHeadlineState> emit,
@@ -239,9 +204,6 @@ class CreateHeadlineBloc
239204
pagination: state.countriesCursor != null
240205
? PaginationOptions(cursor: state.countriesCursor)
241206
: null,
242-
filter: state.countrySearchTerm.isNotEmpty
243-
? {'name': state.countrySearchTerm}
244-
: null,
245207
sort: [const SortOption('name', SortOrder.asc)],
246208
);
247209

lib/content_management/bloc/create_headline/create_headline_event.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ final class CreateHeadlineSubmitted extends CreateHeadlineEvent {
8484
const CreateHeadlineSubmitted();
8585
}
8686

87-
/// Event for when the country search term is changed.
88-
final class CreateHeadlineCountrySearchChanged extends CreateHeadlineEvent {
89-
const CreateHeadlineCountrySearchChanged(this.searchTerm);
90-
final String searchTerm;
91-
@override
92-
List<Object?> get props => [searchTerm];
93-
}
94-
9587
/// Event to request loading more countries.
9688
final class CreateHeadlineLoadMoreCountriesRequested
9789
extends CreateHeadlineEvent {

lib/content_management/bloc/create_headline/create_headline_state.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ final class CreateHeadlineState extends Equatable {
3535
this.countriesHasMore = true,
3636
this.countriesIsLoadingMore = false,
3737
this.countriesCursor,
38-
this.countrySearchTerm = '',
3938
this.contentStatus = ContentStatus.active,
4039
this.exception,
4140
this.createdHeadline,
@@ -55,7 +54,6 @@ final class CreateHeadlineState extends Equatable {
5554
final bool countriesHasMore;
5655
final bool countriesIsLoadingMore;
5756
final String? countriesCursor;
58-
final String countrySearchTerm;
5957
final ContentStatus contentStatus;
6058
final HttpException? exception;
6159
final Headline? createdHeadline;
@@ -85,7 +83,6 @@ final class CreateHeadlineState extends Equatable {
8583
bool? countriesHasMore,
8684
bool? countriesIsLoadingMore,
8785
String? countriesCursor,
88-
String? countrySearchTerm,
8986
ContentStatus? contentStatus,
9087
HttpException? exception,
9188
Headline? createdHeadline,
@@ -106,7 +103,6 @@ final class CreateHeadlineState extends Equatable {
106103
countriesIsLoadingMore:
107104
countriesIsLoadingMore ?? this.countriesIsLoadingMore,
108105
countriesCursor: countriesCursor ?? this.countriesCursor,
109-
countrySearchTerm: countrySearchTerm ?? this.countrySearchTerm,
110106
contentStatus: contentStatus ?? this.contentStatus,
111107
exception: exception,
112108
createdHeadline: createdHeadline ?? this.createdHeadline,
@@ -129,7 +125,6 @@ final class CreateHeadlineState extends Equatable {
129125
countriesHasMore,
130126
countriesIsLoadingMore,
131127
countriesCursor,
132-
countrySearchTerm,
133128
contentStatus,
134129
exception,
135130
createdHeadline,

lib/content_management/bloc/create_source/create_source_bloc.dart

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,9 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
3131
on<CreateSourceHeadquartersChanged>(_onHeadquartersChanged);
3232
on<CreateSourceStatusChanged>(_onStatusChanged);
3333
on<CreateSourceSubmitted>(_onSubmitted);
34-
on<CreateSourceCountrySearchChanged>(
35-
_onCountrySearchChanged,
36-
transformer: droppable(),
37-
);
3834
on<CreateSourceLoadMoreCountriesRequested>(
3935
_onLoadMoreCountriesRequested,
4036
);
41-
on<CreateSourceLanguageSearchChanged>(
42-
_onLanguageSearchChanged,
43-
transformer: droppable(),
44-
);
4537
on<CreateSourceLoadMoreLanguagesRequested>(
4638
_onLoadMoreLanguagesRequested,
4739
);
@@ -186,37 +178,6 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
186178
}
187179
}
188180

189-
Future<void> _onCountrySearchChanged(
190-
CreateSourceCountrySearchChanged event,
191-
Emitter<CreateSourceState> emit,
192-
) async {
193-
await Future<void>.delayed(_searchDebounceDuration);
194-
emit(state.copyWith(countrySearchTerm: event.searchTerm));
195-
try {
196-
final countriesResponse = await _countriesRepository.readAll(
197-
filter: event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null,
198-
sort: [const SortOption('name', SortOrder.asc)],
199-
);
200-
201-
emit(
202-
state.copyWith(
203-
countries: countriesResponse.items,
204-
countriesCursor: countriesResponse.cursor,
205-
countriesHasMore: countriesResponse.hasMore,
206-
),
207-
);
208-
} on HttpException catch (e) {
209-
emit(state.copyWith(status: CreateSourceStatus.failure, exception: e));
210-
} catch (e) {
211-
emit(
212-
state.copyWith(
213-
status: CreateSourceStatus.failure,
214-
exception: UnknownException('An unexpected error occurred: $e'),
215-
),
216-
);
217-
}
218-
}
219-
220181
Future<void> _onLoadMoreCountriesRequested(
221182
CreateSourceLoadMoreCountriesRequested event,
222183
Emitter<CreateSourceState> emit,
@@ -230,9 +191,6 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
230191
pagination: state.countriesCursor != null
231192
? PaginationOptions(cursor: state.countriesCursor)
232193
: null,
233-
filter: state.countrySearchTerm.isNotEmpty
234-
? {'name': state.countrySearchTerm}
235-
: null,
236194
sort: [const SortOption('name', SortOrder.asc)],
237195
);
238196

@@ -263,37 +221,6 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
263221
}
264222
}
265223

266-
Future<void> _onLanguageSearchChanged(
267-
CreateSourceLanguageSearchChanged event,
268-
Emitter<CreateSourceState> emit,
269-
) async {
270-
await Future<void>.delayed(_searchDebounceDuration);
271-
emit(state.copyWith(languageSearchTerm: event.searchTerm));
272-
try {
273-
final languagesResponse = await _languagesRepository.readAll(
274-
filter: event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null,
275-
sort: [const SortOption('name', SortOrder.asc)],
276-
);
277-
278-
emit(
279-
state.copyWith(
280-
languages: languagesResponse.items,
281-
languagesCursor: languagesResponse.cursor,
282-
languagesHasMore: languagesResponse.hasMore,
283-
),
284-
);
285-
} on HttpException catch (e) {
286-
emit(state.copyWith(status: CreateSourceStatus.failure, exception: e));
287-
} catch (e) {
288-
emit(
289-
state.copyWith(
290-
status: CreateSourceStatus.failure,
291-
exception: UnknownException('An unexpected error occurred: $e'),
292-
),
293-
);
294-
}
295-
}
296-
297224
Future<void> _onLoadMoreLanguagesRequested(
298225
CreateSourceLoadMoreLanguagesRequested event,
299226
Emitter<CreateSourceState> emit,
@@ -307,9 +234,6 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
307234
pagination: state.languagesCursor != null
308235
? PaginationOptions(cursor: state.languagesCursor)
309236
: null,
310-
filter: state.languageSearchTerm.isNotEmpty
311-
? {'name': state.languageSearchTerm}
312-
: null,
313237
sort: [const SortOption('name', SortOrder.asc)],
314238
);
315239

lib/content_management/bloc/create_source/create_source_event.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,11 @@ final class CreateSourceSubmitted extends CreateSourceEvent {
7676
const CreateSourceSubmitted();
7777
}
7878

79-
/// Event for when the country search term is changed.
80-
final class CreateSourceCountrySearchChanged extends CreateSourceEvent {
81-
const CreateSourceCountrySearchChanged(this.searchTerm);
82-
final String searchTerm;
83-
@override
84-
List<Object?> get props => [searchTerm];
85-
}
86-
8779
/// Event to request loading more countries.
8880
final class CreateSourceLoadMoreCountriesRequested extends CreateSourceEvent {
8981
const CreateSourceLoadMoreCountriesRequested();
9082
}
9183

92-
/// Event for when the language search term is changed.
93-
final class CreateSourceLanguageSearchChanged extends CreateSourceEvent {
94-
const CreateSourceLanguageSearchChanged(this.searchTerm);
95-
final String searchTerm;
96-
@override
97-
List<Object?> get props => [searchTerm];
98-
}
99-
10084
/// Event to request loading more languages.
10185
final class CreateSourceLoadMoreLanguagesRequested extends CreateSourceEvent {
10286
const CreateSourceLoadMoreLanguagesRequested();

lib/content_management/bloc/create_source/create_source_state.dart

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ final class CreateSourceState extends Equatable {
3333
this.countriesHasMore = true,
3434
this.countriesIsLoadingMore = false,
3535
this.countriesCursor,
36-
this.countrySearchTerm = '',
3736
this.languages = const [],
3837
this.languagesHasMore = true,
3938
this.languagesIsLoadingMore = false,
4039
this.languagesCursor,
41-
this.languageSearchTerm = '',
4240
this.contentStatus = ContentStatus.active,
4341
this.exception,
4442
this.createdSource,
@@ -55,12 +53,10 @@ final class CreateSourceState extends Equatable {
5553
final bool countriesHasMore;
5654
final bool countriesIsLoadingMore;
5755
final String? countriesCursor;
58-
final String countrySearchTerm;
5956
final List<Language> languages;
6057
final bool languagesHasMore;
6158
final bool languagesIsLoadingMore;
6259
final String? languagesCursor;
63-
final String languageSearchTerm;
6460
final ContentStatus contentStatus;
6561
final HttpException? exception;
6662
final Source? createdSource;
@@ -86,12 +82,10 @@ final class CreateSourceState extends Equatable {
8682
bool? countriesHasMore,
8783
bool? countriesIsLoadingMore,
8884
String? countriesCursor,
89-
String? countrySearchTerm,
9085
List<Language>? languages,
9186
bool? languagesHasMore,
9287
bool? languagesIsLoadingMore,
9388
String? languagesCursor,
94-
String? languageSearchTerm,
9589
ContentStatus? contentStatus,
9690
HttpException? exception,
9791
Source? createdSource,
@@ -109,13 +103,11 @@ final class CreateSourceState extends Equatable {
109103
countriesIsLoadingMore:
110104
countriesIsLoadingMore ?? this.countriesIsLoadingMore,
111105
countriesCursor: countriesCursor ?? this.countriesCursor,
112-
countrySearchTerm: countrySearchTerm ?? this.countrySearchTerm,
113106
languages: languages ?? this.languages,
114107
languagesHasMore: languagesHasMore ?? this.languagesHasMore,
115108
languagesIsLoadingMore:
116109
languagesIsLoadingMore ?? this.languagesIsLoadingMore,
117110
languagesCursor: languagesCursor ?? this.languagesCursor,
118-
languageSearchTerm: languageSearchTerm ?? this.languageSearchTerm,
119111
contentStatus: contentStatus ?? this.contentStatus,
120112
exception: exception,
121113
createdSource: createdSource ?? this.createdSource,
@@ -133,16 +125,14 @@ final class CreateSourceState extends Equatable {
133125
headquarters,
134126
countries,
135127
countriesHasMore,
136-
countriesIsLoadingMore,
137-
countriesCursor,
138-
countrySearchTerm,
139-
languages,
140-
languagesHasMore,
141-
languagesIsLoadingMore,
142-
languagesCursor,
143-
languageSearchTerm,
144-
contentStatus,
145-
exception,
128+
countriesIsLoadingMore,
129+
countriesCursor,
130+
languages,
131+
languagesHasMore,
132+
languagesIsLoadingMore,
133+
languagesCursor,
134+
contentStatus,
135+
exception,
146136
createdSource,
147137
];
148138
}

lib/content_management/bloc/edit_headline/edit_headline_bloc.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
3535
on<EditHeadlineCountryChanged>(_onCountryChanged);
3636
on<EditHeadlineStatusChanged>(_onStatusChanged);
3737
on<EditHeadlineSubmitted>(_onSubmitted);
38-
on<EditHeadlineCountrySearchChanged>(
39-
_onCountrySearchChanged,
40-
transformer: droppable(),
41-
);
4238
on<EditHeadlineLoadMoreCountriesRequested>(
4339
_onLoadMoreCountriesRequested,
4440
);
@@ -245,37 +241,6 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
245241
}
246242
}
247243

248-
Future<void> _onCountrySearchChanged(
249-
EditHeadlineCountrySearchChanged event,
250-
Emitter<EditHeadlineState> emit,
251-
) async {
252-
await Future<void>.delayed(_searchDebounceDuration);
253-
emit(state.copyWith(countrySearchTerm: event.searchTerm));
254-
try {
255-
final countriesResponse = await _countriesRepository.readAll(
256-
filter: event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null,
257-
sort: [const SortOption('name', SortOrder.asc)],
258-
);
259-
260-
emit(
261-
state.copyWith(
262-
countries: countriesResponse.items,
263-
countriesCursor: countriesResponse.cursor,
264-
countriesHasMore: countriesResponse.hasMore,
265-
),
266-
);
267-
} on HttpException catch (e) {
268-
emit(state.copyWith(status: EditHeadlineStatus.failure, exception: e));
269-
} catch (e) {
270-
emit(
271-
state.copyWith(
272-
status: EditHeadlineStatus.failure,
273-
exception: UnknownException('An unexpected error occurred: $e'),
274-
),
275-
);
276-
}
277-
}
278-
279244
Future<void> _onLoadMoreCountriesRequested(
280245
EditHeadlineLoadMoreCountriesRequested event,
281246
Emitter<EditHeadlineState> emit,
@@ -289,9 +254,6 @@ class EditHeadlineBloc extends Bloc<EditHeadlineEvent, EditHeadlineState> {
289254
pagination: state.countriesCursor != null
290255
? PaginationOptions(cursor: state.countriesCursor)
291256
: null,
292-
filter: state.countrySearchTerm.isNotEmpty
293-
? {'name': state.countrySearchTerm}
294-
: null,
295257
sort: [const SortOption('name', SortOrder.asc)],
296258
);
297259

0 commit comments

Comments
 (0)