]> cat aescling's git repositories - mastodon.git/blob - app/javascript/themes/glitch/actions/settings.js
Forking glitch theme
[mastodon.git] / app / javascript / themes / glitch / actions / settings.js
1 import axios from 'axios';
2 import { debounce } from 'lodash';
3
4 export const SETTING_CHANGE = 'SETTING_CHANGE';
5 export const SETTING_SAVE = 'SETTING_SAVE';
6
7 export function changeSetting(key, value) {
8 return dispatch => {
9 dispatch({
10 type: SETTING_CHANGE,
11 key,
12 value,
13 });
14
15 dispatch(saveSettings());
16 };
17 };
18
19 const debouncedSave = debounce((dispatch, getState) => {
20 if (getState().getIn(['settings', 'saved'])) {
21 return;
22 }
23
24 const data = getState().get('settings').filter((_, key) => key !== 'saved').toJS();
25
26 axios.put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
27 }, 5000, { trailing: true });
28
29 export function saveSettings() {
30 return (dispatch, getState) => debouncedSave(dispatch, getState);
31 };
This page took 0.084593 seconds and 4 git commands to generate.