logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

settings.js (892B)


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