2022-01-30 09:46:57 -08:00
|
|
|
import { List as ImmutableList } from 'immutable';
|
|
|
|
|
2022-02-02 05:33:12 -08:00
|
|
|
import { MODAL_OPEN, MODAL_CLOSE } from '../actions/modals';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-01-30 09:46:57 -08:00
|
|
|
const initialState = ImmutableList();
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
export default function modal(state = initialState, action) {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case MODAL_OPEN:
|
|
|
|
return state.push({ modalType: action.modalType, modalProps: action.modalProps });
|
|
|
|
case MODAL_CLOSE:
|
|
|
|
if (state.size === 0) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (action.modalType === undefined) {
|
|
|
|
return state.pop();
|
|
|
|
}
|
|
|
|
if (state.some(({ modalType }) => action.modalType === modalType)) {
|
|
|
|
return state.slice(0, state.findLastIndex(({ modalType }) => action.modalType === modalType));
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
default:
|
2022-01-30 09:46:57 -08:00
|
|
|
return state;
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|