2016-08-05 01:43:13 +00:00
|
|
|
import axios from 'axios';
|
2017-02-22 19:29:35 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-06-22 19:58:23 +00:00
|
|
|
|
2018-08-24 21:41:23 +00:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const ROOT_URL = __process.env.API_URL;
|
2016-08-05 01:43:13 +00:00
|
|
|
|
|
|
|
function updatePreferences(formParams, dispatch) {
|
|
|
|
axios.put(`${ROOT_URL}/preferences`, formParams, { withCredentials: true })
|
|
|
|
.then(() => {
|
|
|
|
})
|
2017-02-22 19:29:35 +00:00
|
|
|
.catch(response => dispatch({
|
2016-08-05 01:43:13 +00:00
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
}));
|
|
|
|
}
|
2016-07-06 15:27:39 +00:00
|
|
|
|
2016-08-04 03:45:49 +00:00
|
|
|
export function setFontSize(value) {
|
2016-08-05 01:43:13 +00: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-09 22:45:59 +00:00
|
|
|
fontSize: value
|
2016-08-05 01:43:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-07-11 00:13:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-04 03:45:49 +00:00
|
|
|
export function setIndentation(value) {
|
2016-08-05 01:43:13 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_INDENTATION,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
indentationAmount: value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-07-11 00:13:37 +00:00
|
|
|
};
|
|
|
|
}
|
2016-07-11 02:52:48 +00:00
|
|
|
|
|
|
|
export function indentWithTab() {
|
2016-08-05 01:43:13 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.INDENT_WITH_TAB
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
isTabIndent: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-07-11 02:52:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function indentWithSpace() {
|
2016-08-05 01:43:13 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.INDENT_WITH_SPACE
|
|
|
|
});
|
|
|
|
const state = getState();
|
|
|
|
if (state.user.authenticated) {
|
|
|
|
const formParams = {
|
|
|
|
preferences: {
|
|
|
|
isTabIndent: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updatePreferences(formParams, dispatch);
|
|
|
|
}
|
2016-07-11 02:52:48 +00:00
|
|
|
};
|
|
|
|
}
|
2016-08-09 18:20:54 +00:00
|
|
|
|
|
|
|
export function setAutosave(value) {
|
2016-08-09 20:15:28 +00: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 18:20:54 +00:00
|
|
|
};
|
|
|
|
}
|
2016-08-11 18:09:59 +00:00
|
|
|
|
2019-03-26 19:37:44 +00: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 18:09:59 +00: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 19:50:33 +00: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 18:15:46 +00:00
|
|
|
|
2017-05-31 19:23:30 +00: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 18:15:46 +00:00
|
|
|
export function setTheme(value) {
|
2016-09-28 18:12:01 +00: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 18:15:46 +00:00
|
|
|
};
|
|
|
|
}
|
2017-09-15 16:10:25 +00:00
|
|
|
|
|
|
|
export function setAllAccessibleOutput(value) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(setTextOutput(value));
|
|
|
|
dispatch(setGridOutput(value));
|
|
|
|
dispatch(setSoundOutput(value));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|