2020-08-17 11:23:58 +02:00
|
|
|
import i18next from 'i18next';
|
2020-06-08 12:29:24 +02:00
|
|
|
import apiClient from '../../../utils/apiClient';
|
2017-02-22 20:29:35 +01:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-06-22 21:58:23 +02:00
|
|
|
|
2016-08-05 03:43:13 +02:00
|
|
|
function updatePreferences(formParams, dispatch) {
|
2020-06-08 12:29:24 +02:00
|
|
|
apiClient.put('/preferences', formParams)
|
2016-08-05 03:43:13 +02:00
|
|
|
.then(() => {
|
|
|
|
})
|
2020-04-25 16:48:39 +02:00
|
|
|
.catch((error) => {
|
|
|
|
const { response } = error;
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
});
|
|
|
|
});
|
2016-08-05 03:43:13 +02:00
|
|
|
}
|
2016-07-06 17:27:39 +02:00
|
|
|
|
2016-08-04 05:45:49 +02:00
|
|
|
export function setFontSize(value) {
|
2016-08-05 03:43:13 +02:00
|
|
|
return (dispatch, getState) => { // eslint-disable-line
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_FONT_SIZE,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
2016-08-10 00:45:59 +02:00
|
|
|
fontSize: value
|
2016-08-05 03:43:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-07-11 02:13:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:36:34 +02:00
|
|
|
export function setLineNumbers(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_LINE_NUMBERS,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
lineNumbers: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-09 20:20:54 +02:00
|
|
|
export function setAutosave(value) {
|
2016-08-09 22:15:28 +02:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_AUTOSAVE,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
autosave: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-08-09 20:20:54 +02:00
|
|
|
};
|
|
|
|
}
|
2016-08-11 20:09:59 +02:00
|
|
|
|
2019-03-26 20:37:44 +01:00
|
|
|
export function setLinewrap(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_LINEWRAP,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
linewrap: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:09:59 +02:00
|
|
|
export function setLintWarning(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_LINT_WARNING,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
lintWarning: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-08-12 21:50:33 +02:00
|
|
|
|
|
|
|
export function setTextOutput(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_TEXT_OUTPUT,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
textOutput: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-09-13 20:15:46 +02:00
|
|
|
|
2017-05-31 21:23:30 +02:00
|
|
|
export function setGridOutput(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_GRID_OUTPUT,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
gridOutput: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSoundOutput(value) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_SOUND_OUTPUT,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
soundOutput: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-13 20:15:46 +02:00
|
|
|
export function setTheme(value) {
|
2016-09-28 20:12:01 +02:00
|
|
|
// return {
|
|
|
|
// type: ActionTypes.SET_THEME,
|
|
|
|
// value
|
|
|
|
// };
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_THEME,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
theme: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setAutorefresh(value) {
|
|
|
|
// return {
|
|
|
|
// type: ActionTypes.SET_AUTOREFRESH,
|
|
|
|
// value
|
|
|
|
// };
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_AUTOREFRESH,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
autorefresh: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-09-13 20:15:46 +02:00
|
|
|
};
|
|
|
|
}
|
2017-09-15 18:10:25 +02:00
|
|
|
|
|
|
|
export function setAllAccessibleOutput(value) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(setTextOutput(value));
|
|
|
|
dispatch(setGridOutput(value));
|
|
|
|
dispatch(setSoundOutput(value));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-17 11:23:58 +02:00
|
|
|
export function setLanguage(value, { persistPreference = true } = {}) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
i18next.changeLanguage(value);
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_LANGUAGE,
|
|
|
|
language: value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (persistPreference && state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
language: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|