todos-contra-el-fuego-mobile/lib/redux/fireNotificationReducer.dart
vjrj 7a4c9fb3bc fix: resolve 2 remaining strict analysis errors
- introPage.dart: Convert fireItems to proper static function closure
- mainDrawer.dart: Convert unreadCount int to String for Text widget
2026-03-06 11:21:06 +01:00

50 lines
1.8 KiB
Dart

import 'package:redux/redux.dart';
import '../models/fireNotification.dart';
import 'actions.dart';
final Reducer<List<FireNotification>> fireNotificationReducer = combineReducers<List<FireNotification>>(<Reducer<List<FireNotification>>>[
TypedReducer<List<FireNotification>, AddedFireNotificationAction>(
_addedFireNotification),
TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
_deletedFireNotification),
TypedReducer<List<FireNotification>, UpdatedFireNotificationAction>(
_updatedFireNotification),
TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
_deletedAllFireNotifications),
TypedReducer<List<FireNotification>, ReadedFireNotificationAction>(
_readedFireNotification)
]);
List<FireNotification> _addedFireNotification(
List<FireNotification> notifications, AddedFireNotificationAction action) {
return List.from(notifications)..insert(0, action.notif);
}
List<FireNotification> _deletedFireNotification(
List<FireNotification> notifications,
DeletedFireNotificationAction action) {
return List.from(notifications)..remove(action.notif);
}
List<FireNotification> _updatedFireNotification(
List<FireNotification> notifications,
UpdatedFireNotificationAction action) {
return notifications
.map((FireNotification notif) => notif.id == action.notif.id ? action.notif : notif)
.toList();
}
List<FireNotification> _readedFireNotification(
List<FireNotification> notifications, ReadedFireNotificationAction action) {
return notifications
.map((FireNotification yourLocation) =>
yourLocation.id == action.notif.id ? action.notif : yourLocation)
.toList();
}
List<FireNotification> _deletedAllFireNotifications(
List<FireNotification> notifications,
DeletedAllFireNotificationAction action) {
return <FireNotification>[];
}