-
Notifications
You must be signed in to change notification settings - Fork 0
Fix countrries and languages uncomplete list in the con,tent managment #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fulleni
merged 22 commits into
main
from
fix-countrries-and-languages-uncomplete-list-in-the-con,tent-managment
Jul 31, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c20e7c1
refactor(content_management): improve error handling in CreateSourceBloc
fulleni ca6e320
feat(content_management): add pagination fields to headline states
fulleni 2612cb5
feat(content_management): add pagination events to headline blocs
fulleni b15d07c
feat(content_management): implement search and pagination for countries
fulleni 38614f1
feat(content_management): add country search and pagination
fulleni 204b536
feat(content_management): import bloc_concurrency for enhanced state …
fulleni 4bb564b
feat(content_management): implement paginated logic in headline BLoCs
fulleni 9aa277e
feat(shared): create searchable paginated dropdown form field
fulleni b784d40
feat(content_management): integrate searchable country dropdown
fulleni 09ba20f
feat(content_management): add pagination fields to source states
fulleni 517766b
feat(content_management): add pagination events to source blocs
fulleni 76fd1af
feat(content_management): implement paginated logic in CreateSourceBloc
fulleni 1a8818d
feat(content_management): implement paginated logic in EditSourceBloc
fulleni 97069e7
feat(content_management): integrate searchable dropdowns in source forms
fulleni 90db0c0
refactor(shared): remove obsolete dropdown widgets
fulleni 6058e79
fix(content_management): correct debounce logic and complete handlers
fulleni e1381c4
refactor(widgets): remove unused widget exports
fulleni 0936211
fix(content_management): improve country search and pagination
fulleni 01df3d4
fix(content_management): improve pagination and filtering logic
fulleni 3a0a193
fix(content_management): improve countries filter and pagination
fulleni 5f5e4bb
refactor(content_management): improve type safety in edit source bloc
fulleni 3bb633b
fix(content_management): resolve errors in EditSourceBloc
fulleni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:bloc_concurrency/bloc_concurrency.dart'; | ||
import 'package:core/core.dart'; | ||
import 'package:data_repository/data_repository.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
@@ -8,6 +9,8 @@ import 'package:uuid/uuid.dart'; | |
part 'create_headline_event.dart'; | ||
part 'create_headline_state.dart'; | ||
|
||
const _searchDebounceDuration = Duration(milliseconds: 300); | ||
|
||
/// A BLoC to manage the state of creating a new headline. | ||
class CreateHeadlineBloc | ||
extends Bloc<CreateHeadlineEvent, CreateHeadlineState> { | ||
|
@@ -32,6 +35,12 @@ class CreateHeadlineBloc | |
on<CreateHeadlineCountryChanged>(_onCountryChanged); | ||
on<CreateHeadlineStatusChanged>(_onStatusChanged); | ||
on<CreateHeadlineSubmitted>(_onSubmitted); | ||
on<CreateHeadlineCountrySearchChanged>( | ||
_onCountrySearchChanged, | ||
transformer: restartable(), | ||
); | ||
on<CreateHeadlineLoadMoreCountriesRequested>( | ||
_onLoadMoreCountriesRequested); | ||
} | ||
|
||
final DataRepository<Headline> _headlinesRepository; | ||
|
@@ -46,33 +55,30 @@ class CreateHeadlineBloc | |
) async { | ||
emit(state.copyWith(status: CreateHeadlineStatus.loading)); | ||
try { | ||
final [ | ||
sourcesResponse, | ||
topicsResponse, | ||
countriesResponse, | ||
] = await Future.wait([ | ||
final [sourcesResponse, topicsResponse] = await Future.wait([ | ||
_sourcesRepository.readAll( | ||
sort: [const SortOption('updatedAt', SortOrder.desc)], | ||
), | ||
_topicsRepository.readAll( | ||
sort: [const SortOption('updatedAt', SortOrder.desc)], | ||
), | ||
_countriesRepository.readAll( | ||
sort: [const SortOption('name', SortOrder.asc)], | ||
), | ||
]); | ||
|
||
final sources = (sourcesResponse as PaginatedResponse<Source>).items; | ||
final topics = (topicsResponse as PaginatedResponse<Topic>).items; | ||
final countries = | ||
(countriesResponse as PaginatedResponse<Country>).items; | ||
|
||
final countriesResponse = await _countriesRepository.readAll( | ||
sort: [const SortOption('name', SortOrder.asc)], | ||
); | ||
|
||
emit( | ||
state.copyWith( | ||
status: CreateHeadlineStatus.initial, | ||
sources: sources, | ||
topics: topics, | ||
countries: countries, | ||
countries: countriesResponse.items, | ||
countriesCursor: countriesResponse.cursor, | ||
countriesHasMore: countriesResponse.hasMore, | ||
), | ||
); | ||
} on HttpException catch (e) { | ||
|
@@ -189,4 +195,72 @@ class CreateHeadlineBloc | |
); | ||
} | ||
} | ||
|
||
Future<void> _onCountrySearchChanged( | ||
CreateHeadlineCountrySearchChanged event, | ||
Emitter<CreateHeadlineState> emit, | ||
) async { | ||
await Future<void>.delayed(_searchDebounceDuration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
emit(state.copyWith(countrySearchTerm: event.searchTerm)); | ||
try { | ||
final countriesResponse = await _countriesRepository.readAll( | ||
filter: | ||
event.searchTerm.isNotEmpty ? {'name': event.searchTerm} : null, | ||
sort: [const SortOption('name', SortOrder.asc)], | ||
); | ||
|
||
emit( | ||
state.copyWith( | ||
countries: countriesResponse.items, | ||
countriesCursor: countriesResponse.cursor, | ||
countriesHasMore: countriesResponse.hasMore, | ||
), | ||
); | ||
} on HttpException catch (e) { | ||
emit(state.copyWith(status: CreateHeadlineStatus.failure, exception: e)); | ||
} catch (e) { | ||
emit( | ||
state.copyWith( | ||
status: CreateHeadlineStatus.failure, | ||
exception: UnknownException('An unexpected error occurred: $e'), | ||
), | ||
); | ||
} | ||
} | ||
|
||
Future<void> _onLoadMoreCountriesRequested( | ||
CreateHeadlineLoadMoreCountriesRequested event, | ||
Emitter<CreateHeadlineState> emit, | ||
) async { | ||
if (!state.countriesHasMore) return; | ||
|
||
try { | ||
final countriesResponse = await _countriesRepository.readAll( | ||
pagination: state.countriesCursor != null | ||
? PaginationOptions(cursor: state.countriesCursor) | ||
: null, | ||
filter: state.countrySearchTerm.isNotEmpty | ||
? {'name': state.countrySearchTerm} | ||
: null, | ||
sort: [const SortOption('name', SortOrder.asc)], | ||
); | ||
|
||
emit( | ||
state.copyWith( | ||
countries: List.of(state.countries)..addAll(countriesResponse.items), | ||
countriesCursor: countriesResponse.cursor, | ||
countriesHasMore: countriesResponse.hasMore, | ||
), | ||
); | ||
} on HttpException catch (e) { | ||
emit(state.copyWith(status: CreateHeadlineStatus.failure, exception: e)); | ||
} catch (e) { | ||
emit( | ||
state.copyWith( | ||
status: CreateHeadlineStatus.failure, | ||
exception: UnknownException('An unexpected error occurred: $e'), | ||
), | ||
); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For handling search input with a delay,
bloc_concurrency
provides adebounce
transformer that is more idiomatic for this use case thanrestartable()
combined with a manualFuture.delayed
. Usingdebounce
will make the intent clearer and the event handler code cleaner.