alpinesmuseum-public/assets/js/redux/reducers/ui.js
2022-09-23 07:38:37 +05:30

68 lines
1.4 KiB
JavaScript

import {
SHOW_SPINNER,
HIDE_SPINNER,
OPEN_DETAIL,
SHOW_NEXT_ITEM,
SHOW_PREV_ITEM,
CLOSE_DETAIL,
TOGGEL_MENU,
TOGGEL_SHOWING_SEARCH_RESULTS,
TOGGLE_PARTICIPATED,
SET_MAGNET_INSTANCE,
SET_PRE_LAUNCH,
SET_INTERNAL
} from '../actions/ui';
const initUi = {
pending: false,
activeItem: null,
menuOpen: false,
showingSearchResults: false,
participated: false,
magnetInstance: undefined,
isPreLaunch: undefined,
isInternal: undefined
};
export default function uiReducer(state = initUi, action) {
switch (action.type) {
case SHOW_SPINNER:
return { ...state, pending: true };
case HIDE_SPINNER:
return { ...state, pending: false };
case OPEN_DETAIL:
return { ...state, activeItem: action.item };
case SHOW_NEXT_ITEM:
return { ...state, activeItem: state.activeItem + 1 };
case SHOW_PREV_ITEM:
return { ...state, activeItem: state.activeItem - 1 };
case CLOSE_DETAIL:
return { ...state, activeItem: null };
case TOGGEL_MENU:
return { ...state, menuOpen: !state.menuOpen };
case TOGGEL_SHOWING_SEARCH_RESULTS:
return { ...state, showingSearchResults: action.payload };
case TOGGLE_PARTICIPATED:
return { ...state, participated: action.payload };
case SET_MAGNET_INSTANCE:
return { ...state, magnetInstance: action.payload };
case SET_PRE_LAUNCH:
return { ...state, isPreLaunch: action.payload };
case SET_INTERNAL:
return { ...state, isInternal: action.payload };
default:
return state;
}
}