Created
October 21, 2017 04:26
-
-
Save justincorrigible/41b1f7503e86c21fda6c5fe3811a9b6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {UI} from './initialStates'; | |
import {REHYDRATE} from 'redux-persist/constants'; | |
import {searchFilters} from '../helpers/'; | |
export const isToggled = (state, toggle) => { | |
switch(toggle) { | |
case 'collapsed': | |
return state.collapsed; | |
case 'expanded': | |
return state.expanded; | |
case 'searching': | |
return state.searching; | |
} | |
return; | |
}; | |
export default (state = UI, action) => { | |
// console.log('reducer UI', action); | |
switch(action.type) { | |
case REHYDRATE: | |
return { | |
...state, | |
...action.payload.uiState, | |
settingsLoaded: true | |
}; | |
case 'TOGGLE_ENGINES': | |
return {...state, showEngines: !state.showEngines}; | |
case 'TOGGLE_LEGEND': | |
return { | |
...state, | |
legend: { | |
...state.legend, | |
visible: !state.legend.visible | |
} | |
}; | |
case 'TOGGLE_NIGHTMODE': | |
return {...state, nightMode: !state.nightMode}; | |
case 'TOGGLE_OPTIONS_MENU': | |
return {...state, showSettingsMenu: !state.showSettingsMenu}; | |
case 'TOGGLE_OWNERS': | |
return { ...state, showOwners: !state.showOwners }; | |
case 'TOGGLE_DRAWER': { | |
console.log(action, state.drawer, | |
state.drawer.requestInfo === action.payload.requestInfo) | |
return action.payload === undefined ? | |
{ ...state, | |
drawer: { | |
...state.drawer, | |
open: [], | |
} | |
} : | |
(action.payload.name === 'locations' && | |
(!action.payload.requestInfo || state.drawer.requestInfo === action.payload.requestInfo)) || | |
(action.payload.name !== 'locations' && state.drawer.open.includes(action.payload.name)) ? | |
{ ...state, | |
drawer: { | |
...state.drawer, | |
open: state.drawer.open.filter( | |
option => option !== action.payload.name), | |
requestInfo: false, | |
} | |
} : | |
{ ...state, | |
drawer: { | |
...state.drawer, | |
open: state.drawer.open.concat(action.payload.name), | |
requestInfo: action.payload.requestInfo, | |
} | |
};} | |
case 'TOGGLE_TOOLBAR': | |
return { ...state, showToolbar: !state.showToolbar }; | |
case 'TOGGLE_TRIPSLIST': | |
return {...state, showTripsList: !state.showTripsList}; | |
case 'TOGGLE_WAYPOINTS': | |
return {...state, showWaypoints: !state.showWaypoints}; | |
case 'DISPLAY_DIALOGUE': | |
return { ...state, dialogues: action.payload }; | |
case 'CLEAR_DIALOGUES': | |
return { ...state, dialogues: []}; | |
case 'UPDATE_SEARCH_BAR': | |
return { ...state, searchString: action.payload}; | |
case 'CLEAR_SEARCH': | |
return {...state, searching: false, searchString: ''}; | |
case 'CLEAR_FILTERS': | |
return {...state, filters: []}; | |
case 'MAP_ICONS_FETCHED': | |
return { | |
...state, | |
legend: { | |
...state.legend, | |
data: action.payload | |
} | |
}; | |
case 'VIEWS_FETCHED': | |
return {...state, viewsFetched: true}; | |
case 'SCREEN_RESIZE': | |
return {...state, screenWidth: action.screenWidth}; | |
case 'TRIPS_EXPAND_ALL': | |
if (state.expanded == false) { | |
return { | |
...state, | |
collapsed: false, | |
expanded: true | |
}; | |
} | |
// break omitted on purpose | |
case 'TRIP_COLLAPSE_TOGGLE': | |
if (!action.condition) { | |
return { | |
...state, | |
expanded: false | |
}; | |
} | |
else if (action.condition === 'expand') break; | |
// break omitted on purpose | |
case 'TRIPS_COLLAPSE_ALL': | |
return { | |
...state, | |
collapsed: !state.collapsed, | |
expanded: false | |
}; | |
case 'TRIPS_FILTER': { | |
const filtersArray = | |
state.filters.includes(action.payload) ? | |
state.filters.filter(word => word != action.payload) : | |
state.filters.concat(action.payload); | |
return { | |
...state, | |
filters: filtersArray | |
}; | |
} | |
case 'TRIPS_SEARCH': { | |
return {...state, searching: searchFilters(action.payload)}; | |
} | |
} | |
return state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment