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

Wyświetl plik

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

Wyświetl plik

@ -1,6 +1,7 @@
import { import {
SOAPBOX_CONFIG_REQUEST_SUCCESS, SOAPBOX_CONFIG_REQUEST_SUCCESS,
SOAPBOX_CONFIG_REQUEST_FAIL, SOAPBOX_CONFIG_REQUEST_FAIL,
SOAPBOX_POST_SUCCESS,
} from '../actions/soapbox'; } from '../actions/soapbox';
import { Map as ImmutableMap, fromJS } from 'immutable'; 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))); return defaultState.merge(ImmutableMap(fromJS(action.soapboxConfig)));
case SOAPBOX_CONFIG_REQUEST_FAIL: case SOAPBOX_CONFIG_REQUEST_FAIL:
return defaultState; return defaultState;
case SOAPBOX_POST_SUCCESS:
const soapbox = ImmutableMap(fromJS(action.soapboxConfig)).configs[0].value[0].tuple[1];
return soapbox;
default: default:
return state; return state;
} }