Skip to content

Commit

Permalink
Fix multiple error snackbars not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
viplmad committed Feb 5, 2024
1 parent 48c5d75 commit d46094c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lib/ui/list/item_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ abstract class ItemList<
},
child: RefreshIndicator(
onRefresh: () async {
BlocProvider.of<K>(context).add(ReloadItemList());
BlocProvider.of<K>(context).add(const ReloadItemList());
},
child: BlocBuilder<K, ItemListState>(
builder: (BuildContext context, ItemListState state) {
Expand All @@ -293,7 +293,7 @@ abstract class ItemList<
return ItemError(
title: AppLocalizations.of(context)!.somethingWentWrongString,
onRetryTap: () =>
BlocProvider.of<K>(context).add(ReloadItemList()),
BlocProvider.of<K>(context).add(const ReloadItemList()),
);
}

Expand Down Expand Up @@ -447,7 +447,7 @@ abstract class ItemListBody<T extends PrimaryModel,
arguments: DetailArguments<T>(
item: item,
onChange: () {
BlocProvider.of<K>(context).add(ReloadItemList());
BlocProvider.of<K>(context).add(const ReloadItemList());
},
),
);
Expand Down
4 changes: 4 additions & 0 deletions logic/lib/bloc/calendar_manager/calendar_manager_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ class CalendarManagerBloc
Emitter<CalendarManagerState> emit,
) {
emit(CalendarNotLoaded(event.error, event.errorDescription));

emit(
CalendarManagerInitialised(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ abstract class ItemDetailManagerBloc<T extends PrimaryModel, N extends Object,
Emitter<ItemDetailManagerState> emit,
) {
emit(ItemDetailNotLoaded(event.error, event.errorDescription));

emit(
ItemDetailManagerInitialised(),
);
}

void _handleError(Object e, Emitter<ItemDetailManagerState> emit) {
Expand Down
27 changes: 7 additions & 20 deletions logic/lib/bloc/item_list/item_list_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ abstract class ItemListBloc<T extends PrimaryModel, N extends Object,
}) : super(ItemListLoading()) {
on<LoadItemList>(_mapLoadToState);
on<ReloadItemList>(_mapReloadToState);
on<UpdateItemList<T>>(_mapUpdateListToState);
on<UpdateView>(_mapUpdateViewToState);
on<UpdatePage>(_mapUpdatePageToState);
on<UpdateStyle>(_mapUpdateStyleToState);
Expand Down Expand Up @@ -50,9 +49,11 @@ abstract class ItemListBloc<T extends PrimaryModel, N extends Object,
final int viewIndex = (state as ItemListLoaded<T>).viewIndex;
final ListStyle style = (state as ItemListLoaded<T>).style;

emit(
ItemListLoading(),
);
if (!event.silent) {
emit(
ItemListLoading(),
);
}

try {
final List<T> items = await getAllWithView(viewIndex);
Expand Down Expand Up @@ -90,20 +91,6 @@ abstract class ItemListBloc<T extends PrimaryModel, N extends Object,
}
}

void _mapUpdateListToState(
UpdateItemList<T> event,
Emitter<ItemListState> emit,
) {
emit(
ItemListLoaded<T>(
event.items,
event.viewIndex,
event.page,
event.style,
),
);
}

void _mapUpdateViewToState(
UpdateView event,
Emitter<ItemListState> emit,
Expand Down Expand Up @@ -198,11 +185,11 @@ abstract class ItemListBloc<T extends PrimaryModel, N extends Object,
}

void _mapAddedToEvent(ItemAdded<T> managerState) {
add(ReloadItemList());
add(const ReloadItemList(silent: true));
}

void _mapDeletedToEvent(ItemDeleted<T> managerState) {
add(ReloadItemList());
add(const ReloadItemList(silent: true));
}

@override
Expand Down
29 changes: 6 additions & 23 deletions logic/lib/bloc/item_list/item_list_event.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'package:equatable/equatable.dart';

import 'package:game_oclock_client/api.dart' show PrimaryModel;

import 'package:logic/model/model.dart' show ListStyle;

abstract class ItemListEvent extends Equatable {
const ItemListEvent();

Expand All @@ -13,30 +9,17 @@ abstract class ItemListEvent extends Equatable {

class LoadItemList extends ItemListEvent {}

class ReloadItemList extends ItemListEvent {}
class ReloadItemList extends ItemListEvent {
const ReloadItemList({this.silent = false});

class UpdateItemList<T extends PrimaryModel> extends ItemListEvent {
const UpdateItemList(
this.items,
this.viewIndex,
this.page,
this.style,
);

final List<T> items;
final int viewIndex;
final int page;
final ListStyle style;
final bool silent;

@override
List<Object> get props => <Object>[items, viewIndex, page, style];
List<Object> get props => <Object>[silent];

@override
String toString() => 'UpdateItemList { '
'items: $items, '
'viewIndex: $viewIndex, '
'page: $page, '
'style: $style'
String toString() => 'ReloadItemList { '
'silent: $silent'
' }';
}

Expand Down
4 changes: 4 additions & 0 deletions logic/lib/bloc/item_list_manager/item_list_manager_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ abstract class ItemListManagerBloc<T extends PrimaryModel, N extends Object,
Emitter<ItemListManagerState> emit,
) {
emit(ItemListNotLoaded(event.error, event.errorDescription));

emit(
ItemListManagerInitialised(),
);
}

Future<T> _create(AddItem<N> event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ abstract class ItemRelationManagerBloc<W extends PrimaryModel, N extends Object>
Emitter<ItemRelationManagerState> emit,
) {
emit(ItemRelationNotLoaded(event.error, event.errorDescription));

emit(
ItemRelationManagerInitialised(),
);
}

@protected
Expand Down
4 changes: 4 additions & 0 deletions logic/lib/bloc/review_manager/review_manager_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ class ReviewManagerBloc extends Bloc<ReviewManagerEvent, ReviewManagerState> {
Emitter<ReviewManagerState> emit,
) {
emit(ReviewNotLoaded(event.error, event.errorDescription));

emit(
ReviewManagerInitialised(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class ServerSettingsManagerBloc
) {
emit(ServerSettingsNotLoaded(event.error, event.errorDescription));

// TODO Check others missing initialised
emit(
ServerSettingsManagerInitialised(),
);
Expand Down

0 comments on commit d46094c

Please sign in to comment.