Import Instance into store
This commit is contained in:
parent
e33b621fb9
commit
8ec0e6e82a
4 changed files with 47 additions and 1 deletions
29
app/gabsocial/actions/instance.js
Normal file
29
app/gabsocial/actions/instance.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import api from '../api';
|
||||||
|
|
||||||
|
export const INSTANCE_IMPORT = 'INSTANCE_IMPORT';
|
||||||
|
export const INSTANCE_FAIL = 'INSTANCE_FAIL';
|
||||||
|
|
||||||
|
export function fetchInstance() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
api(getState).get(`/api/v1/instance`).then(response => {
|
||||||
|
dispatch(importInstance(response.data));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(instanceFail(error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function importInstance(instance) {
|
||||||
|
return {
|
||||||
|
type: INSTANCE_IMPORT,
|
||||||
|
instance
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function instanceFail(error) {
|
||||||
|
return {
|
||||||
|
type: INSTANCE_FAIL,
|
||||||
|
error,
|
||||||
|
skipAlert: true,
|
||||||
|
};
|
||||||
|
};
|
|
@ -17,6 +17,7 @@ import { getLocale } from '../locales';
|
||||||
import initialState from '../initial_state';
|
import initialState from '../initial_state';
|
||||||
import { me } from '../initial_state';
|
import { me } from '../initial_state';
|
||||||
import ErrorBoundary from '../components/error_boundary';
|
import ErrorBoundary from '../components/error_boundary';
|
||||||
|
import { fetchInstance } from 'gabsocial/actions/instance';
|
||||||
import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox';
|
import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox';
|
||||||
|
|
||||||
const { localeData, messages } = getLocale();
|
const { localeData, messages } = getLocale();
|
||||||
|
@ -26,8 +27,9 @@ export const store = configureStore();
|
||||||
const hydrateAction = hydrateStore(initialState);
|
const hydrateAction = hydrateStore(initialState);
|
||||||
|
|
||||||
store.dispatch(hydrateAction);
|
store.dispatch(hydrateAction);
|
||||||
store.dispatch(fetchCustomEmojis());
|
store.dispatch(fetchInstance());
|
||||||
store.dispatch(fetchSoapboxConfig());
|
store.dispatch(fetchSoapboxConfig());
|
||||||
|
store.dispatch(fetchCustomEmojis());
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const account = state.getIn(['accounts', me]);
|
const account = state.getIn(['accounts', me]);
|
||||||
|
|
|
@ -39,6 +39,7 @@ import group_editor from './group_editor';
|
||||||
import sidebar from './sidebar';
|
import sidebar from './sidebar';
|
||||||
import patron from './patron';
|
import patron from './patron';
|
||||||
import soapbox from './soapbox';
|
import soapbox from './soapbox';
|
||||||
|
import instance from './instance';
|
||||||
|
|
||||||
const reducers = {
|
const reducers = {
|
||||||
dropdown_menu,
|
dropdown_menu,
|
||||||
|
@ -81,6 +82,7 @@ const reducers = {
|
||||||
sidebar,
|
sidebar,
|
||||||
patron,
|
patron,
|
||||||
soapbox,
|
soapbox,
|
||||||
|
instance,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default combineReducers(reducers);
|
export default combineReducers(reducers);
|
||||||
|
|
13
app/gabsocial/reducers/instance.js
Normal file
13
app/gabsocial/reducers/instance.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { INSTANCE_IMPORT } from '../actions/instance';
|
||||||
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
const initialState = ImmutableMap();
|
||||||
|
|
||||||
|
export default function instance(state = initialState, action) {
|
||||||
|
switch(action.type) {
|
||||||
|
case INSTANCE_IMPORT:
|
||||||
|
return ImmutableMap(fromJS(action.instance));
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in a new issue