aboutsummaryrefslogtreecommitdiff
path: root/modern/src/store/geofences.js
blob: 0c8396536b9954d555162559fce793c2613c9932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createSlice } from '@reduxjs/toolkit';

const { reducer, actions } = createSlice({
  name: 'geofences',
  initialState: {
    items: {},
    selectedId: null,
  },
  reducers: {
    select(state, action) {
      state.selectedId = action.payload.id;
    },
    unselect(state, action) {
      state.selectedId = null;
    },
    refresh(state, action) {
      state.items = {};
      action.payload.forEach((item) => state.items[item.id] = item);
    },
    update(state, action) {
      action.payload.forEach((item) => state.items[item.id] = item);
    },
  },
});

export { actions as geofencesActions };
export { reducer as geofencesReducer };