-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Actions): ajouter sur la page d'accueil
- Loading branch information
Showing
29 changed files
with
433 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/lib/features/actions/home/infrastructure/home_actions_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:app/core/infrastructure/endpoints.dart'; | ||
import 'package:app/core/infrastructure/http_client_helpers.dart'; | ||
import 'package:app/features/actions/list/domain/action_item.dart'; | ||
import 'package:app/features/actions/list/infrastructure/action_item_mapper.dart'; | ||
import 'package:app/features/authentification/core/infrastructure/dio_http_client.dart'; | ||
import 'package:app/features/theme/core/domain/theme_type.dart'; | ||
import 'package:fpdart/fpdart.dart'; | ||
|
||
class HomeActionsRepository { | ||
const HomeActionsRepository({required final DioHttpClient client}) | ||
: _client = client; | ||
|
||
final DioHttpClient _client; | ||
|
||
Future<Either<Exception, List<ActionItem>>> fetch({ | ||
required final ThemeType? themeType, | ||
}) async { | ||
final queryParameters = {'status': 'en_cours'}; | ||
if (themeType != null) { | ||
queryParameters.putIfAbsent('thematique', () => themeType.name); | ||
} | ||
final response = await _client.get( | ||
Uri(path: Endpoints.actions, queryParameters: queryParameters).toString(), | ||
); | ||
|
||
if (isResponseUnsuccessful(response.statusCode)) { | ||
return Left(Exception('Erreur lors de la récupération des actions')); | ||
} | ||
|
||
final json = response.data! as List<dynamic>; | ||
|
||
return Right( | ||
json | ||
.take(5) | ||
.map( | ||
(final e) => ActionItemMapper.fromJson(e as Map<String, dynamic>), | ||
) | ||
.toList(), | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/lib/features/actions/home/presentation/bloc/home_actions_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:app/features/actions/home/infrastructure/home_actions_repository.dart'; | ||
import 'package:app/features/actions/home/presentation/bloc/home_actions_event.dart'; | ||
import 'package:app/features/actions/home/presentation/bloc/home_actions_state.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class HomeActionsBloc extends Bloc<HomeActionsEvent, HomeActionsState> { | ||
HomeActionsBloc({required final HomeActionsRepository repository}) | ||
: super(const HomeActionsInitial()) { | ||
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)), | ||
); | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/lib/features/actions/home/presentation/bloc/home_actions_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:app/features/theme/core/domain/theme_type.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
@immutable | ||
sealed class HomeActionsEvent extends Equatable { | ||
const HomeActionsEvent(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
@immutable | ||
final class HomeActionsLoadRequested extends HomeActionsEvent { | ||
const HomeActionsLoadRequested(this.themeType); | ||
|
||
final ThemeType? themeType; | ||
|
||
@override | ||
List<Object?> get props => [themeType]; | ||
} |
26 changes: 26 additions & 0 deletions
26
app/lib/features/actions/home/presentation/bloc/home_actions_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:app/features/actions/list/domain/action_item.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
@immutable | ||
sealed class HomeActionsState extends Equatable { | ||
const HomeActionsState(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
@immutable | ||
final class HomeActionsInitial extends HomeActionsState { | ||
const HomeActionsInitial(); | ||
} | ||
|
||
@immutable | ||
final class HomeActionsLoadSuccess extends HomeActionsState { | ||
const HomeActionsLoadSuccess({required this.actions}); | ||
|
||
final List<ActionItem> actions; | ||
|
||
@override | ||
List<Object> get props => [actions]; | ||
} |
123 changes: 123 additions & 0 deletions
123
app/lib/features/actions/home/presentation/widgets/actions_section.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import 'package:app/core/presentation/widgets/fondamentaux/shadows.dart'; | ||
import 'package:app/features/accueil/presentation/widgets/title_section.dart'; | ||
import 'package:app/features/actions/detail/presentation/pages/action_detail_page.dart'; | ||
import 'package:app/features/actions/home/presentation/bloc/home_actions_bloc.dart'; | ||
import 'package:app/features/actions/home/presentation/bloc/home_actions_event.dart'; | ||
import 'package:app/features/actions/home/presentation/bloc/home_actions_state.dart'; | ||
import 'package:app/features/actions/list/domain/action_item.dart'; | ||
import 'package:app/features/actions/list/presentation/pages/action_list_page.dart'; | ||
import 'package:app/features/theme/core/domain/theme_type.dart'; | ||
import 'package:app/features/theme/presentation/widgets/theme_type_tag.dart'; | ||
import 'package:app/l10n/l10n.dart'; | ||
import 'package:dsfr/dsfr.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
class ActionsSection extends StatelessWidget { | ||
const ActionsSection({super.key, this.themeType}); | ||
|
||
final ThemeType? themeType; | ||
|
||
@override | ||
Widget build(final BuildContext context) { | ||
context.read<HomeActionsBloc>().add(HomeActionsLoadRequested(themeType)); | ||
|
||
return BlocBuilder<HomeActionsBloc, HomeActionsState>( | ||
builder: (final context, final state) => switch (state) { | ||
HomeActionsInitial() => const SizedBox.shrink(), | ||
HomeActionsLoadSuccess() => _Section(state), | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _Section extends StatelessWidget { | ||
const _Section(this.state); | ||
|
||
final HomeActionsLoadSuccess state; | ||
|
||
@override | ||
Widget build(final context) => Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const TitleSection( | ||
title: Localisation.homeActionsTitle, | ||
subTitle: Localisation.homeActionsSubTitle, | ||
), | ||
const SizedBox(height: DsfrSpacings.s2w), | ||
SingleChildScrollView( | ||
scrollDirection: Axis.horizontal, | ||
padding: EdgeInsets.zero, | ||
clipBehavior: Clip.none, | ||
child: IntrinsicHeight( | ||
child: Row( | ||
children: state.actions | ||
.map(_Action.new) | ||
.separator(const SizedBox(width: DsfrSpacings.s2w)) | ||
.toList(), | ||
), | ||
), | ||
), | ||
const SizedBox(height: DsfrSpacings.s2w), | ||
Align( | ||
alignment: Alignment.centerLeft, | ||
child: DsfrLink.md( | ||
label: Localisation.homeActionsLink, | ||
onTap: () async => | ||
GoRouter.of(context).pushNamed(ActionListPage.name), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
|
||
class _Action extends StatelessWidget { | ||
const _Action(this.item); | ||
|
||
final ActionItem item; | ||
|
||
@override | ||
Widget build(final context) { | ||
const width = 250.0; | ||
|
||
return GestureDetector( | ||
onTap: () async { | ||
final result = await GoRouter.of(context).pushNamed( | ||
ActionDetailPage.name, | ||
pathParameters: {'id': item.id.value}, | ||
); | ||
|
||
if (result != true || !context.mounted) {} | ||
// if (context.mounted) { | ||
// context.read<MissionHomeBloc>().add(const MissionHomeFetch()); | ||
// } | ||
}, | ||
child: DecoratedBox( | ||
decoration: const ShapeDecoration( | ||
color: Colors.white, | ||
shadows: recommandationOmbre, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(DsfrSpacings.s1w)), | ||
), | ||
), | ||
child: SizedBox( | ||
width: width, | ||
child: Padding( | ||
padding: const EdgeInsets.all(DsfrSpacings.s2w), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
ThemeTypeTag(themeType: item.themeType), | ||
const SizedBox(height: DsfrSpacings.s1w), | ||
Expanded( | ||
child: Text(item.titre, style: const DsfrTextStyle.bodyLg()), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import 'package:app/features/actions/core/domain/action_id.dart'; | ||
import 'package:app/features/actions/core/domain/action_status.dart'; | ||
import 'package:app/features/theme/core/domain/theme_type.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
final class ActionItem extends Equatable { | ||
const ActionItem({ | ||
required this.id, | ||
required this.themeType, | ||
required this.titre, | ||
required this.status, | ||
}); | ||
|
||
final ActionId id; | ||
final ThemeType themeType; | ||
final String titre; | ||
final ActionStatus status; | ||
|
||
@override | ||
List<Object?> get props => [id, titre, status]; | ||
List<Object?> get props => [id, themeType, titre, status]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.