import { createReducer, on } from '@ngrx/store'; import { YapNotification } from '@onepoint-yap/dashboard'; import { NotificationActions } from './notification.actions'; export interface NotificationState { list: YapNotification[]; } export const initialNotificationState: NotificationState = { list: [] }; export const notificationReducer = createReducer( initialNotificationState, on(NotificationActions.add, (state, action) => ({ ...state, list: [...state.list, { ...action.notification, read: action.notification.read ?? false }] })), on(NotificationActions.read, (state, action) => { const list = JSON.parse(JSON.stringify(state.list)); const modified = list.find((notif: YapNotification) => notif.id === action.id) ?? { read: false }; modified.read = true; return { ...state, list }; }) );