Add patchMe action

This commit is contained in:
Alex Gleason 2020-04-21 15:53:32 -05:00
parent 8a5807f5df
commit 68f36685b7
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 35 additions and 8 deletions

View file

@ -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,
};
};

View file

@ -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));
});