From b72f522d43540b8a1738c2b518f657b44cc3ae77 Mon Sep 17 00:00:00 2001 From: Lucas SAUDON Date: Thu, 19 Dec 2024 15:59:57 +0100 Subject: [PATCH] =?UTF-8?q?fix(actions):=20rafra=C3=AEchir=20apr=C3=A8s=20?= =?UTF-8?q?modification=20d'une=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/bloc/home_actions_bloc.dart | 25 +++++++++++++++++-- .../presentation/bloc/home_actions_event.dart | 8 ++++++ .../presentation/bloc/home_actions_state.dart | 11 +++++--- .../presentation/widgets/actions_section.dart | 8 +++--- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/lib/features/actions/home/presentation/bloc/home_actions_bloc.dart b/app/lib/features/actions/home/presentation/bloc/home_actions_bloc.dart index cf9fedf6..0b07c3ce 100644 --- a/app/lib/features/actions/home/presentation/bloc/home_actions_bloc.dart +++ b/app/lib/features/actions/home/presentation/bloc/home_actions_bloc.dart @@ -9,9 +9,30 @@ class HomeActionsBloc extends Bloc { on((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((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), + ), + ); + } + }); } } diff --git a/app/lib/features/actions/home/presentation/bloc/home_actions_event.dart b/app/lib/features/actions/home/presentation/bloc/home_actions_event.dart index 62cf9810..b179ea33 100644 --- a/app/lib/features/actions/home/presentation/bloc/home_actions_event.dart +++ b/app/lib/features/actions/home/presentation/bloc/home_actions_event.dart @@ -19,3 +19,11 @@ final class HomeActionsLoadRequested extends HomeActionsEvent { @override List get props => [themeType]; } + +@immutable +final class HomeActionsRefreshRequested extends HomeActionsEvent { + const HomeActionsRefreshRequested(); + + @override + List get props => []; +} diff --git a/app/lib/features/actions/home/presentation/bloc/home_actions_state.dart b/app/lib/features/actions/home/presentation/bloc/home_actions_state.dart index 3139b03c..8a9e67bd 100644 --- a/app/lib/features/actions/home/presentation/bloc/home_actions_state.dart +++ b/app/lib/features/actions/home/presentation/bloc/home_actions_state.dart @@ -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'; @@ -7,7 +8,7 @@ sealed class HomeActionsState extends Equatable { const HomeActionsState(); @override - List get props => []; + List get props => []; } @immutable @@ -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 actions; @override - List get props => [actions]; + List get props => [actions, themeType]; } diff --git a/app/lib/features/actions/home/presentation/widgets/actions_section.dart b/app/lib/features/actions/home/presentation/widgets/actions_section.dart index 1d9165a7..52e6d2f0 100644 --- a/app/lib/features/actions/home/presentation/widgets/actions_section.dart +++ b/app/lib/features/actions/home/presentation/widgets/actions_section.dart @@ -103,9 +103,11 @@ class _Action extends StatelessWidget { ); if (result != true || !context.mounted) {} - // if (context.mounted) { - // context.read().add(const MissionHomeFetch()); - // } + if (context.mounted) { + context + .read() + .add(const HomeActionsRefreshRequested()); + } }, child: DecoratedBox( decoration: const ShapeDecoration(