From 68f36685b705dfeade029e380f2a9a85b6a9334f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Apr 2020 15:53:32 -0500 Subject: [PATCH] Add patchMe action --- app/gabsocial/actions/me.js | 28 ++++++++++++++++++++++++++++ app/gabsocial/actions/settings.js | 15 +++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/gabsocial/actions/me.js b/app/gabsocial/actions/me.js index 202289aaf..679ee0397 100644 --- a/app/gabsocial/actions/me.js +++ b/app/gabsocial/actions/me.js @@ -6,6 +6,9 @@ export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS'; export const ME_FETCH_FAIL = 'ME_FETCH_FAIL'; export const ME_FETCH_SKIP = 'ME_FETCH_SKIP'; +export const ME_PATCH_REQUEST = 'ME_PATCH_REQUEST'; +export const ME_PATCH_FAIL = 'ME_PATCH_FAIL'; + function hasToken(getState) { const accessToken = getState().getIn(['auth', 'user', 'access_token']); return Boolean(accessToken); @@ -29,6 +32,18 @@ export function fetchMe() { }; } +export function patchMe(params) { + return (dispatch, getState) => { + return api(getState) + .patch('/api/v1/accounts/update_credentials', params) + .then(response => { + dispatch(fetchMeSuccess(response.data)); + }).catch(error => { + dispatch(patchMeFail(error)); + }); + }; +} + export function fetchMeRequest() { return { type: ME_FETCH_REQUEST, @@ -49,3 +64,16 @@ export function fetchMeFail(error) { skipAlert: true, }; }; + +export function patchMeRequest() { + return { + type: ME_PATCH_REQUEST, + }; +} + +export function patchMeFail(error) { + return { + type: ME_PATCH_FAIL, + error, + }; +}; diff --git a/app/gabsocial/actions/settings.js b/app/gabsocial/actions/settings.js index f2aa32802..3616a7af6 100644 --- a/app/gabsocial/actions/settings.js +++ b/app/gabsocial/actions/settings.js @@ -1,7 +1,6 @@ -import api from '../api'; import { debounce } from 'lodash'; import { showAlertForError } from './alerts'; -import { fetchMeSuccess } from 'gabsocial/actions/me'; +import { patchMe } from 'gabsocial/actions/me'; export const SETTING_CHANGE = 'SETTING_CHANGE'; export const SETTING_SAVE = 'SETTING_SAVE'; @@ -21,18 +20,18 @@ export function changeSetting(path, value) { }; const debouncedSave = debounce((dispatch, getState) => { - if (!getState().get('me')) return; - if (getState().getIn(['settings', 'saved'])) return; + const state = getState(); + if (!state.get('me')) return; + if (state.getIn(['settings', 'saved'])) return; - const data = getState().get('settings').delete('saved').toJS(); + const data = state.get('settings').delete('saved').toJS(); - api(getState).patch('/api/v1/accounts/update_credentials', { + dispatch(patchMe({ pleroma_settings_store: { [FE_NAME]: data, }, - }).then(response => { + })).then(response => { dispatch({ type: SETTING_SAVE }); - dispatch(fetchMeSuccess(response.data)); }).catch(error => { dispatch(showAlertForError(error)); });