feat(unionflow): ajout Spec-Kit, constitution, mission mutuelles
- Config Spec-Kit pour Spec-Driven Development - CONSTITUTION.md + .specify/memory/constitution.md - Commandes Cursor /speckit.*, règles projet - Mission: associations + mutuelles d'épargne et de financement - .gitignore: versionner config spec-kit unionflow Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
library notifications_bloc;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../data/models/notification_model.dart';
|
||||
import '../../data/repositories/notification_repository.dart';
|
||||
|
||||
part 'notifications_event.dart';
|
||||
part 'notifications_state.dart';
|
||||
|
||||
class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
|
||||
final NotificationRepository _repository;
|
||||
|
||||
NotificationsBloc(this._repository) : super(const NotificationsInitial()) {
|
||||
on<LoadNotifications>(_onLoadNotifications);
|
||||
on<MarkNotificationAsRead>(_onMarkAsRead);
|
||||
on<RefreshNotifications>(_onRefresh);
|
||||
}
|
||||
|
||||
Future<void> _onLoadNotifications(
|
||||
LoadNotifications event,
|
||||
Emitter<NotificationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const NotificationsLoading());
|
||||
final notifications = await _repository.getNotificationsByMembre(event.membreId);
|
||||
final nonLues = notifications.where((n) => !n.estLue).length;
|
||||
emit(NotificationsLoaded(notifications: notifications, nonLuesCount: nonLues));
|
||||
} on DioException catch (e) {
|
||||
emit(NotificationsError(_networkError(e)));
|
||||
} catch (e) {
|
||||
emit(NotificationsError('Erreur lors du chargement : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onMarkAsRead(
|
||||
MarkNotificationAsRead event,
|
||||
Emitter<NotificationsState> emit,
|
||||
) async {
|
||||
try {
|
||||
await _repository.marquerCommeLue(event.notificationId);
|
||||
final currentState = state;
|
||||
if (currentState is NotificationsLoaded) {
|
||||
final updated = currentState.notifications.map((n) {
|
||||
if (n.id == event.notificationId) {
|
||||
return NotificationModel(
|
||||
id: n.id,
|
||||
typeNotification: n.typeNotification,
|
||||
priorite: n.priorite,
|
||||
statut: 'LUE',
|
||||
sujet: n.sujet,
|
||||
corps: n.corps,
|
||||
dateEnvoiPrevue: n.dateEnvoiPrevue,
|
||||
dateEnvoi: n.dateEnvoi,
|
||||
dateLecture: DateTime.now(),
|
||||
donneesAdditionnelles: n.donneesAdditionnelles,
|
||||
membreId: n.membreId,
|
||||
organisationId: n.organisationId,
|
||||
);
|
||||
}
|
||||
return n;
|
||||
}).toList();
|
||||
final nonLues = updated.where((n) => !n.estLue).length;
|
||||
emit(NotificationMarkedAsRead(notifications: updated, nonLuesCount: nonLues));
|
||||
}
|
||||
} catch (e) {
|
||||
// Echec silencieux : ne pas bloquer l'UI
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(
|
||||
RefreshNotifications event,
|
||||
Emitter<NotificationsState> emit,
|
||||
) async {
|
||||
add(LoadNotifications(membreId: event.membreId));
|
||||
}
|
||||
|
||||
String _networkError(DioException e) {
|
||||
final code = e.response?.statusCode;
|
||||
if (code == 401) return 'Non autorisé.';
|
||||
if (code == 403) return 'Accès refusé.';
|
||||
if (code != null && code >= 500) return 'Erreur serveur.';
|
||||
return 'Erreur réseau. Vérifiez votre connexion.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
part of 'notifications_bloc.dart';
|
||||
|
||||
abstract class NotificationsEvent extends Equatable {
|
||||
const NotificationsEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoadNotifications extends NotificationsEvent {
|
||||
final String membreId;
|
||||
final bool onlyUnread;
|
||||
const LoadNotifications({required this.membreId, this.onlyUnread = false});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membreId, onlyUnread];
|
||||
}
|
||||
|
||||
class MarkNotificationAsRead extends NotificationsEvent {
|
||||
final String notificationId;
|
||||
const MarkNotificationAsRead(this.notificationId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [notificationId];
|
||||
}
|
||||
|
||||
class RefreshNotifications extends NotificationsEvent {
|
||||
final String membreId;
|
||||
const RefreshNotifications(this.membreId);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membreId];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
part of 'notifications_bloc.dart';
|
||||
|
||||
abstract class NotificationsState extends Equatable {
|
||||
const NotificationsState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class NotificationsInitial extends NotificationsState {
|
||||
const NotificationsInitial();
|
||||
}
|
||||
|
||||
class NotificationsLoading extends NotificationsState {
|
||||
const NotificationsLoading();
|
||||
}
|
||||
|
||||
class NotificationsLoaded extends NotificationsState {
|
||||
final List<NotificationModel> notifications;
|
||||
final int nonLuesCount;
|
||||
|
||||
const NotificationsLoaded({
|
||||
required this.notifications,
|
||||
required this.nonLuesCount,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [notifications, nonLuesCount];
|
||||
}
|
||||
|
||||
class NotificationMarkedAsRead extends NotificationsState {
|
||||
final List<NotificationModel> notifications;
|
||||
final int nonLuesCount;
|
||||
|
||||
const NotificationMarkedAsRead({
|
||||
required this.notifications,
|
||||
required this.nonLuesCount,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [notifications, nonLuesCount];
|
||||
}
|
||||
|
||||
class NotificationsError extends NotificationsState {
|
||||
final String message;
|
||||
const NotificationsError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
library notifications_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../bloc/notifications_bloc.dart';
|
||||
import 'notifications_page.dart';
|
||||
|
||||
/// Wrapper qui fournit le NotificationsBloc à la NotificationsPage
|
||||
class NotificationsPageWrapper extends StatelessWidget {
|
||||
const NotificationsPageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<NotificationsBloc>(
|
||||
create: (_) => GetIt.instance<NotificationsBloc>(),
|
||||
child: const NotificationsPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user