2016-06-22 21:58:23 +02:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-08-05 03:43:13 +02:00
|
|
|
import axios from 'axios';
|
2016-06-22 21:58:23 +02:00
|
|
|
|
2016-08-05 03:43:13 +02:00
|
|
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
|
|
|
|
|
|
|
function updatePreferences(formParams, dispatch) {
|
|
|
|
axios.put(`${ROOT_URL}/preferences`, formParams, { withCredentials: true })
|
|
|
|
.then(() => {
|
|
|
|
})
|
|
|
|
.catch((response) => dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
}));
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-04 05:45:49 +02:00
|
|
|
export function setIndentation(value) {
|
2016-08-05 03:43:13 +02: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 02:13:37 +02:00
|
|
|
};
|
|
|
|
}
|
2016-07-11 04:52:48 +02:00
|
|
|
|
|
|
|
export function indentWithTab() {
|
2016-08-05 03:43:13 +02: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 04:52:48 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function indentWithSpace() {
|
2016-08-05 03:43:13 +02: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 04:52:48 +02:00
|
|
|
};
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
}
|