Skip to content
Snippets Groups Projects
Select Git revision
  • 79fc439508f2b98373702a21ea34fb4ac9e7f098
  • master default protected
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.2
  • 1.1.1
  • 1.1.0
  • 1.0.19
  • 1.0.18
  • 1.0.17
  • 1.0.16
  • 1.0.15
  • 1.0.14
  • 1.0.13
  • 1.0.12
  • 1.0.10
  • 1.0.9
  • 1.0.8
22 results

EventReducer.js

  • Forked from KSZK / DevTeam / kszkepzes / old / kszkepzes-frontend
    Source project has a limited visibility.
    EventReducer.js 2.71 KiB
    import {
      GET_EVENTS,
      GET_EVENT_BY_ID,
      VISITOR_CHANGE,
      WRITE_EVENT,
      ADD_EVENT,
      DELETE_EVENT,
      CLEAR_WRITE,
      ABSENT_CHANGE,
      CHANGE_NO,
    } from '../actions/types';
    
    const INITIAL_STATE = { events: [], newEvent: {} };
    
    export default (state = INITIAL_STATE, action) => {
      switch (action.type) {
        case GET_EVENTS:
          return { ...state, events: [...action.payload] };
        case GET_EVENT_BY_ID:
          return { ...state, selectedEvent: action.payload };
        case VISITOR_CHANGE:
          if (state.selectedEvent.visitors.includes(action.payload)) {
            // Benne van nem kell megváltoztatni
            return { ...state }
          }
          if (state.selectedEvent.absent.indexOf(action.payload) > -1) {
            // Ha az absentbe van ki kell venni
            state.selectedEvent.absent.splice(state.selectedEvent.absent.indexOf(action.payload), 1);
          }
          state.selectedEvent.visitors.push(action.payload)
          return {
            ...state,
            selectedEvent: {
              ...state.selectedEvent,
              visitors: state.selectedEvent.visitors,
              absent: state.selectedEvent.absent,
            },
          };
        case ABSENT_CHANGE:
          if (state.selectedEvent.absent.includes(action.payload)) {
            return { ...state };
          }
          if (state.selectedEvent.visitors.indexOf(action.payload) > -1) {
            state.selectedEvent.visitors.splice(state.selectedEvent.visitors.indexOf(action.payload), 1);
          }
          state.selectedEvent.absent.push(action.payload);
          return {
            ...state,
            selectedEvent: {
              ...state.selectedEvent,
              visitors: state.selectedEvent.visitors,
              absent: state.selectedEvent.absent,
            },
          };
        case CHANGE_NO:
          if (state.selectedEvent.visitors.indexOf(action.payload) > -1) {
            state.selectedEvent.visitors.splice(state.selectedEvent.visitors.indexOf(action.payload), 1);
          }
          if (state.selectedEvent.absent.indexOf(action.payload) > -1) {
            // Ha az absentbe van ki kell venni
            state.selectedEvent.absent.splice(state.selectedEvent.absent.indexOf(action.payload), 1);
          }
          return {
            ...state,
            selectedEvent: {
              ...state.selectedEvent,
              visitors: state.selectedEvent.visitors,
              absent: state.selectedEvent.absent,
            },
          };