Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2311 | Rev 3583 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2311 Rev 3582
Línea 1... Línea 1...
1
import { v4 as uuid } from 'uuid'
1
import { v4 as uuid } 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
}
-
 
7
 
6
};
8
const notificationReducer = (
-
 
9
  state = NotificationInitialState,
-
 
10
  { type, payload }
7
 
11
) => {
8
const notificationReducer = (state = NotificationInitialState, { type, payload }) => {
12
  switch (type) {
9
  switch (type) {
Línea 13... Línea 10...
13
    case notificationActionTypes.ADD_NOTIFICATION: {
10
    case notificationActionTypes.ADD_NOTIFICATION: {
14
      const newNotification = { ...payload, id: uuid() }
11
      const newNotification = { ...payload, id: uuid() };
15
 
12
 
Línea 16... Línea 13...
16
      const alreadyExist = state.notifications.find(
13
      const alreadyExist = state.notifications.find(
Línea 17... Línea 14...
17
        (notification) => notification.msg === newNotification.msg
14
        (notification) => notification.msg === newNotification.msg
18
      )
15
      );
19
 
16
 
20
      if (alreadyExist) return state
17
      if (alreadyExist) return state;
21
 
18
 
22
      return {
19
      return {
23
        ...state,
20
        ...state,
24
        notifications: [newNotification, ...state.notifications]
21
        notifications: [newNotification, ...state.notifications]
25
      }
22
      };
26
    }
23
    }
27
    case notificationActionTypes.REMOVE_NOTIFICATION: {
-
 
28
      const idToFilter = payload
-
 
29
      return {
24
    case notificationActionTypes.REMOVE_NOTIFICATION: {
30
        ...state,
25
      const idToFilter = payload;
Línea 31... Línea 26...
31
        notifications: state.notifications.filter(
26
      return {
32
          (element) => element.id !== idToFilter
27
        ...state,
33
        )
28
        notifications: state.notifications.filter((element) => element.id !== idToFilter)
34
      }
29
      };
Línea 35... Línea 30...
35
    }
30
    }