p5.js-web-editor/client/modules/IDE/reducers/preferences.js
ov 3333dd41fa
Persistence Language Functionality to Store Language in User Preferences (#1536)
* Entry points to introduce persistence in language selection
* setLanguage action changes both the state and the i18next language
* Ensure language change applies to all pages on load

Co-authored-by: Andrew Nicolaou <me@andrewnicolaou.co.uk>
2020-08-17 11:23:58 +02:00

50 lines
1.7 KiB
JavaScript

import i18next from 'i18next';
import * as ActionTypes from '../../../constants';
const initialState = {
fontSize: 18,
autosave: true,
linewrap: true,
lineNumbers: true,
lintWarning: false,
textOutput: false,
gridOutput: false,
soundOutput: false,
theme: 'light',
autorefresh: false,
language: 'en-US'
};
const preferences = (state = initialState, action) => {
switch (action.type) {
case ActionTypes.SET_FONT_SIZE:
return Object.assign({}, state, { fontSize: action.value });
case ActionTypes.SET_AUTOSAVE:
return Object.assign({}, state, { autosave: action.value });
case ActionTypes.SET_LINEWRAP:
return Object.assign({}, state, { linewrap: action.value });
case ActionTypes.SET_LINT_WARNING:
return Object.assign({}, state, { lintWarning: action.value });
case ActionTypes.SET_TEXT_OUTPUT:
return Object.assign({}, state, { textOutput: action.value });
case ActionTypes.SET_GRID_OUTPUT:
return Object.assign({}, state, { gridOutput: action.value });
case ActionTypes.SET_SOUND_OUTPUT:
return Object.assign({}, state, { soundOutput: action.value });
case ActionTypes.SET_PREFERENCES:
return action.preferences;
case ActionTypes.SET_THEME:
return Object.assign({}, state, { theme: action.value });
case ActionTypes.SET_AUTOREFRESH:
return Object.assign({}, state, { autorefresh: action.value });
case ActionTypes.SET_LINE_NUMBERS:
return Object.assign({}, state, { lineNumbers: action.value });
case ActionTypes.SET_LANGUAGE:
return Object.assign({}, state, { language: action.language });
default:
return state;
}
};
export default preferences;