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.

31 lines
803 B

  1. import api from 'flavours/glitch/util/api';
  2. import { debounce } from 'lodash';
  3. export const SETTING_CHANGE = 'SETTING_CHANGE';
  4. export const SETTING_SAVE = 'SETTING_SAVE';
  5. export function changeSetting(path, value) {
  6. return dispatch => {
  7. dispatch({
  8. type: SETTING_CHANGE,
  9. path,
  10. value,
  11. });
  12. dispatch(saveSettings());
  13. };
  14. };
  15. const debouncedSave = debounce((dispatch, getState) => {
  16. if (getState().getIn(['settings', 'saved'])) {
  17. return;
  18. }
  19. const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS();
  20. api(getState).put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
  21. }, 5000, { trailing: true });
  22. export function saveSettings() {
  23. return (dispatch, getState) => debouncedSave(dispatch, getState);
  24. };