Drafted pushing soapbox object to Redux store on SOAPBOX_POST_SUCCESS

preload
crockwave 2020-07-30 19:39:41 -05:00
rodzic bba5be4463
commit c6f3816f77
3 zmienionych plików z 22 dodań i 21 usunięć

Wyświetl plik

@ -3,9 +3,9 @@ import api from '../api';
export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS';
export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL';
export const SOAPBOX_PATCH_REQUEST = 'SOAPBOX_PATCH_REQUEST';
export const SOAPBOX_PATCH_SUCCESS = 'SOAPBOX_PATCH_SUCCESS';
export const SOAPBOX_PATCH_FAIL = 'SOAPBOX_PATCH_FAIL';
export const SOAPBOX_POST_REQUEST = 'SOAPBOX_POST_REQUEST';
export const SOAPBOX_POST_SUCCESS = 'SOAPBOX_POST_REQUEST';
export const SOAPBOX_POST_FAIL = 'SOAPBOX_POST_REQUEST';
export function fetchSoapboxConfig() {
return (dispatch, getState) => {
@ -47,38 +47,35 @@ export function soapboxConfigFail(error) {
};
}
export function patchSoapbox(params) {
console.log(params);
export function postSoapbox(params) {
return (dispatch, getState) => {
dispatch(patchSoapboxRequest());
dispatch(postSoapboxRequest());
return api(getState)
.patch('/api/pleroma/admin/config', params)
.post('/api/pleroma/admin/config', params)
.then(response => {
dispatch(patchSoapboxSuccess(response.data));
dispatch(postSoapboxSuccess(response.data));
}).catch(error => {
dispatch(patchSoapboxFail(error));
dispatch(postSoapboxFail(error));
});
};
}
export function patchSoapboxRequest() {
export function postSoapboxRequest() {
return {
type: SOAPBOX_PATCH_REQUEST,
type: SOAPBOX_POST_REQUEST,
};
}
export function patchSoapboxSuccess(me) {
return (dispatch, getState) => {
dispatch({
type: SOAPBOX_PATCH_SUCCESS,
me,
});
export function postSoapboxSuccess(soapboxConfig) {
return {
type: SOAPBOX_POST_SUCCESS,
soapboxConfig,
};
}
export function patchSoapboxFail(error) {
export function postSoapboxFail(error) {
return {
type: SOAPBOX_PATCH_FAIL,
type: SOAPBOX_POST_FAIL,
error,
};
};

Wyświetl plik

@ -17,7 +17,7 @@ import {
Map as ImmutableMap,
List as ImmutableList,
} from 'immutable';
import { patchSoapbox } from 'soapbox/actions/soapbox';
import { postSoapbox } from 'soapbox/actions/soapbox';
const messages = defineMessages({
heading: { id: 'column.soapbox_settings', defaultMessage: 'Soapbox settings' },
@ -164,7 +164,7 @@ class ConfigSoapbox extends ImmutablePureComponent {
handleSubmit = (event) => {
const { dispatch } = this.props;
dispatch(patchSoapbox(this.getParams())).then(() => {
dispatch(postSoapbox(this.getParams())).then(() => {
this.setState({ isLoading: false });
}).catch((error) => {
this.setState({ isLoading: false });

Wyświetl plik

@ -1,6 +1,7 @@
import {
SOAPBOX_CONFIG_REQUEST_SUCCESS,
SOAPBOX_CONFIG_REQUEST_FAIL,
SOAPBOX_POST_SUCCESS,
} from '../actions/soapbox';
import { Map as ImmutableMap, fromJS } from 'immutable';
@ -16,6 +17,9 @@ export default function soapbox(state = initialState, action) {
return defaultState.merge(ImmutableMap(fromJS(action.soapboxConfig)));
case SOAPBOX_CONFIG_REQUEST_FAIL:
return defaultState;
case SOAPBOX_POST_SUCCESS:
const soapbox = ImmutableMap(fromJS(action.soapboxConfig)).configs[0].value[0].tuple[1];
return soapbox;
default:
return state;
}