You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
774 B
32 lines
774 B
8 years ago
|
import axios from 'axios';
|
||
7 years ago
|
import { debounce } from 'lodash';
|
||
8 years ago
|
|
||
|
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
||
7 years ago
|
export const SETTING_SAVE = 'SETTING_SAVE';
|
||
8 years ago
|
|
||
|
export function changeSetting(key, value) {
|
||
8 years ago
|
return dispatch => {
|
||
|
dispatch({
|
||
|
type: SETTING_CHANGE,
|
||
|
key,
|
||
|
value,
|
||
|
});
|
||
|
|
||
|
dispatch(saveSettings());
|
||
8 years ago
|
};
|
||
|
};
|
||
8 years ago
|
|
||
7 years ago
|
const debouncedSave = debounce((dispatch, getState) => {
|
||
|
if (getState().getIn(['settings', 'saved'])) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
const data = getState().get('settings').filter((_, key) => key !== 'saved').toJS();
|
||
|
|
||
|
axios.put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
|
||
|
}, 5000, { trailing: true });
|
||
|
|
||
8 years ago
|
export function saveSettings() {
|
||
7 years ago
|
return (dispatch, getState) => debouncedSave(dispatch, getState);
|
||
8 years ago
|
};
|