Skip to content
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

fix(actions): rafraîchir après modification d'une action #417

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading