The code powering m.abunchtell.com https://m.abunchtell.com
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

  1. import axios from 'axios';
  2. import { debounce } from 'lodash';
  3. export const SETTING_CHANGE = 'SETTING_CHANGE';
  4. export const SETTING_SAVE = 'SETTING_SAVE';
  5. export function changeSetting(key, value) {
  6. return dispatch => {
  7. dispatch({
  8. type: SETTING_CHANGE,
  9. key,
  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((_, key) => key !== 'saved').toJS();
  20. axios.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. };