Skip to content

Commit

Permalink
Fix multiple state evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
DeD1rk committed Feb 1, 2023
1 parent b6c050f commit 88b536d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
13 changes: 7 additions & 6 deletions lib/blocs/album_list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ class AlbumListCubit extends PaginatedCubit<ListAlbum> {
@override
Future<void> more() async {
// Ignore calls to `more()` if there is no data, or already more coming.
if (state is! ResultsListState ||
state is LoadingMoreListState ||
state is DoneListState) return;
final oldState = state;
if (oldState is! ResultsListState ||
oldState is LoadingMoreListState ||
oldState is DoneListState) return;

final oldState = state as ResultsListState<ListAlbum>;
final resultsState = state as ResultsListState<ListAlbum>;

emit(LoadingMoreListState.from(oldState));
emit(LoadingMoreListState.from(resultsState));
try {
final query = _searchQuery;

Expand All @@ -80,7 +81,7 @@ class AlbumListCubit extends PaginatedCubit<ListAlbum> {
// changed since the request was made.
if (query != _searchQuery) return;

final albums = state.results + albumsResponse.results;
final albums = resultsState.results + albumsResponse.results;
final isDone = albums.length == albumsResponse.count;

_nextOffset += pageSize;
Expand Down
13 changes: 7 additions & 6 deletions lib/blocs/member_list_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ class MemberListCubit extends PaginatedCubit<ListMember> {
@override
Future<void> more() async {
// Ignore calls to `more()` if there is no data, or already more coming.
if (state is! ResultsListState ||
state is LoadingMoreListState ||
state is DoneListState) return;
final oldState = state;
if (oldState is! ResultsListState ||
oldState is LoadingMoreListState ||
oldState is DoneListState) return;

final oldState = state as ResultsListState<ListMember>;
final resultsState = state as ResultsListState<ListMember>;

emit(LoadingMoreListState.from(oldState));
emit(LoadingMoreListState.from(resultsState));
try {
final query = _searchQuery;

Expand All @@ -80,7 +81,7 @@ class MemberListCubit extends PaginatedCubit<ListMember> {
// changed since the request was made.
if (query != _searchQuery) return;

final members = oldState.results + membersResponse.results;
final members = resultsState.results + membersResponse.results;
final isDone = members.length == membersResponse.count;

_nextOffset += pageSize;
Expand Down
13 changes: 7 additions & 6 deletions lib/blocs/registrations_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ class RegistrationsCubit extends PaginatedCubit<EventRegistration> {
@override
Future<void> more() async {
// Ignore calls to `more()` if there is no data, or already more coming.
if (state is! ResultsListState ||
state is LoadingMoreListState ||
state is DoneListState) return;
final oldState = state;
if (oldState is! ResultsListState ||
oldState is LoadingMoreListState ||
oldState is DoneListState) return;

final oldState = state as ResultsListState<EventRegistration>;
final resultsState = oldState as ResultsListState<EventRegistration>;

emit(LoadingMoreListState.from(oldState));
emit(LoadingMoreListState.from(resultsState));
try {
var listResponse = await api.getEventRegistrations(
pk: eventPk,
limit: pageSize,
offset: _nextOffset,
);

final registrations = state.results + listResponse.results;
final registrations = resultsState.results + listResponse.results;
final isDone = registrations.length == listResponse.count;

_nextOffset += pageSize;
Expand Down

0 comments on commit 88b536d

Please sign in to comment.