-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathside_bar_reducer.js
50 lines (47 loc) · 1.73 KB
/
side_bar_reducer.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { SIDEBAR_TOGGLED, WINDOW_RESIZE, RESET_SIDEBAR_STATE } from '../actions/side_bar_actions';
const defaultState = {
sidebarState: false,
sidebarResponse: true,
sidebarType: 'flex',
};
const SideBarReducer = (state = defaultState, action) => {
switch(action.type) {
case SIDEBAR_TOGGLED: {
if (!state.sidebarState) {
if (action.windowWidth === 'overlay') {
const newState = { sidebarState: true, sidebarType: 'overlay' };
return Object.assign({}, state, newState);
} else {
return { sidebarState: true, sidebarType: 'flex', sidebarResponse: true };
}
} else {
if (action.windowWidth === 'overlay') {
const newState = { sidebarState: false, sidebarType: 'flex' };
return Object.assign({}, state, newState);
} else {
const newState = { sidebarState: false, sidebarResponse: false };
return Object.assign({}, state, newState);
}
}
}
case WINDOW_RESIZE: {
if (action.windowDirection === 'widen') {
if (state.sidebarType === 'overlay') {
return Object.assign({}, state, { sidebarType: 'flex', sidebarResponse: true });
}
else if (state.sidebarResponse) {
return Object.assign({}, state, { sidebarState: true });
}
} else if (state.sidebarType === 'flex') {
return Object.assign({}, state, { sidebarState: false });
}
return state;
}
case RESET_SIDEBAR_STATE: {
const newSideBarState = !['video_show', 'video_form'].includes(action.component) && window.innerWidth >= 1277;
return Object.assign({}, state, { sidebarState: newSideBarState });
}
default: return state;
}
};
export default SideBarReducer;