Add patchMe action
This commit is contained in:
parent
8a5807f5df
commit
68f36685b7
2 changed files with 35 additions and 8 deletions
|
@ -6,6 +6,9 @@ export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS';
|
||||||
export const ME_FETCH_FAIL = 'ME_FETCH_FAIL';
|
export const ME_FETCH_FAIL = 'ME_FETCH_FAIL';
|
||||||
export const ME_FETCH_SKIP = 'ME_FETCH_SKIP';
|
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) {
|
function hasToken(getState) {
|
||||||
const accessToken = getState().getIn(['auth', 'user', 'access_token']);
|
const accessToken = getState().getIn(['auth', 'user', 'access_token']);
|
||||||
return Boolean(accessToken);
|
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() {
|
export function fetchMeRequest() {
|
||||||
return {
|
return {
|
||||||
type: ME_FETCH_REQUEST,
|
type: ME_FETCH_REQUEST,
|
||||||
|
@ -49,3 +64,16 @@ export function fetchMeFail(error) {
|
||||||
skipAlert: true,
|
skipAlert: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function patchMeRequest() {
|
||||||
|
return {
|
||||||
|
type: ME_PATCH_REQUEST,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function patchMeFail(error) {
|
||||||
|
return {
|
||||||
|
type: ME_PATCH_FAIL,
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import api from '../api';
|
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { showAlertForError } from './alerts';
|
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_CHANGE = 'SETTING_CHANGE';
|
||||||
export const SETTING_SAVE = 'SETTING_SAVE';
|
export const SETTING_SAVE = 'SETTING_SAVE';
|
||||||
|
@ -21,18 +20,18 @@ export function changeSetting(path, value) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const debouncedSave = debounce((dispatch, getState) => {
|
const debouncedSave = debounce((dispatch, getState) => {
|
||||||
if (!getState().get('me')) return;
|
const state = getState();
|
||||||
if (getState().getIn(['settings', 'saved'])) return;
|
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: {
|
pleroma_settings_store: {
|
||||||
[FE_NAME]: data,
|
[FE_NAME]: data,
|
||||||
},
|
},
|
||||||
}).then(response => {
|
})).then(response => {
|
||||||
dispatch({ type: SETTING_SAVE });
|
dispatch({ type: SETTING_SAVE });
|
||||||
dispatch(fetchMeSuccess(response.data));
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(showAlertForError(error));
|
dispatch(showAlertForError(error));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue