Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 5309
Línea 1... Línea 1...
1
import { v1 } from "uuid";
1
import { v1 } from 'uuid'
2
import { notificationActionTypes } from "./notification.types";
2
import { notificationActionTypes } from './notification.types'
Línea 3... Línea 3...
3
 
3
 
4
const NotificationInitialState = {
4
const NotificationInitialState = {
5
  notifications: [],
5
  notifications: []
Línea 6... Línea 6...
6
};
6
}
7
 
7
 
8
const notificationReducer = (
8
const notificationReducer = (
9
  state = NotificationInitialState,
9
  state = NotificationInitialState,
10
  { type, payload }
10
  { type, payload }
11
) => {
11
) => {
12
  switch (type) {
12
  switch (type) {
13
    case notificationActionTypes.ADD_NOTIFICATION:
13
    case notificationActionTypes.ADD_NOTIFICATION:
14
      const newNotification = { ...payload, id: v1() };
14
      const newNotification = { ...payload, id: v1() }
15
      return {
15
      return {
16
        ...state,
16
        ...state,
17
        notifications: [newNotification, ...state.notifications],
17
        notifications: [newNotification, ...state.notifications]
18
      };
18
      }
19
    case notificationActionTypes.REMOVE_NOTIFICATION:
19
    case notificationActionTypes.REMOVE_NOTIFICATION:
20
      const idToFilter = payload;
20
      const idToFilter = payload
21
      return {
21
      return {
22
        ...state,
22
        ...state,
23
        notifications: state.notifications.filter(
23
        notifications: state.notifications.filter(
24
          (element) => element.id !== idToFilter
24
          (element) => element.id !== idToFilter
Línea 25... Línea 25...
25
        ),
25
        )
26
      };
26
      }
27
 
27
 
28
    default:
28
    default:
Línea 29... Línea 29...
29
      return state;
29
      return state