Skip to content

Commit

Permalink
fix(actions): rafraîchir après modification d'une action
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaudon committed Dec 19, 2024
1 parent 8cccd4b commit b72f522
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,30 @@ class HomeActionsBloc extends Bloc<HomeActionsEvent, HomeActionsState> {
on<HomeActionsLoadRequested>((final event, final emit) async {
final result = await repository.fetch(themeType: event.themeType);
result.fold(
(final l) => emit(const HomeActionsLoadSuccess(actions: [])),
(final r) => emit(HomeActionsLoadSuccess(actions: r)),
(final l) => emit(
HomeActionsLoadSuccess(
themeType: event.themeType,
actions: const [],
),
),
(final r) => emit(
HomeActionsLoadSuccess(themeType: event.themeType, actions: r),
),
);
});
on<HomeActionsRefreshRequested>((final event, final emit) async {
switch (state) {
case HomeActionsInitial():
return;
case final HomeActionsLoadSuccess aState:
final result = await repository.fetch(themeType: aState.themeType);
emit(
HomeActionsLoadSuccess(
themeType: aState.themeType,
actions: result.fold((final l) => const [], (final r) => r),
),
);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ final class HomeActionsLoadRequested extends HomeActionsEvent {
@override
List<Object?> get props => [themeType];
}

@immutable
final class HomeActionsRefreshRequested extends HomeActionsEvent {
const HomeActionsRefreshRequested();

@override
List<Object?> get props => [];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app/features/actions/list/domain/action_item.dart';
import 'package:app/features/theme/core/domain/theme_type.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';

Expand All @@ -7,7 +8,7 @@ sealed class HomeActionsState extends Equatable {
const HomeActionsState();

@override
List<Object> get props => [];
List<Object?> get props => [];
}

@immutable
Expand All @@ -17,10 +18,14 @@ final class HomeActionsInitial extends HomeActionsState {

@immutable
final class HomeActionsLoadSuccess extends HomeActionsState {
const HomeActionsLoadSuccess({required this.actions});
const HomeActionsLoadSuccess({
required this.themeType,
required this.actions,
});

final ThemeType? themeType;
final List<ActionItem> actions;

@override
List<Object> get props => [actions];
List<Object?> get props => [actions, themeType];
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ class _Action extends StatelessWidget {
);

if (result != true || !context.mounted) {}
// if (context.mounted) {
// context.read<MissionHomeBloc>().add(const MissionHomeFetch());
// }
if (context.mounted) {
context
.read<HomeActionsBloc>()
.add(const HomeActionsRefreshRequested());
}
},
child: DecoratedBox(
decoration: const ShapeDecoration(
Expand Down

0 comments on commit b72f522

Please sign in to comment.