drawerReducer.ts 1003 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
import { ActionType, getType } from 'typesafe-actions';

import { DrawerState, defaultDrawerState } from './drawerState';
import * as drawerActions from './drawerActions';

export default function drawer(
  state: DrawerState = defaultDrawerState,
  action: ActionType<typeof drawerActions>
): DrawerState {
  switch (action.type) {
11
    case getType(drawerActions.changeDrawerViewForGenome):
12 13
      return {
        ...state,
14
        drawerView: { ...state.drawerView, ...action.payload }
15
      };
16 17 18 19 20 21 22
    case getType(drawerActions.toggleDrawerForGenome):
      const genomeId = Object.keys(action.payload)[0];
      let drawerOpenedValue = Object.values(action.payload)[0];
      let drawerViewForGenome = drawerOpenedValue
        ? state.drawerView[genomeId]
        : '';

23 24
      return {
        ...state,
25
        isDrawerOpened: { ...state.isDrawerOpened, ...action.payload },
26
        drawerView: { ...state.drawerView, [genomeId]: drawerViewForGenome }
27 28 29 30 31
      };
    default:
      return state;
  }
}