mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
Save static config to redux
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import * as actions from '../constants/static';
|
||||
|
||||
export const setStaticConfiguration = config => ({
|
||||
type: actions.SET_STATIC_CONFIGURATION,
|
||||
config,
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
const prefix = `TALK_FRAMEWORK`;
|
||||
|
||||
export const SET_STATIC_CONFIGURATION = `${prefix}_SET_STATIC_CONFIGURATION`;
|
||||
@@ -0,0 +1,7 @@
|
||||
import auth from './auth';
|
||||
import staticConfiguration from './static';
|
||||
|
||||
export default {
|
||||
auth,
|
||||
static: staticConfiguration,
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as actions from '../constants/static';
|
||||
|
||||
const initialState = {};
|
||||
|
||||
export default function auth(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case actions.SET_STATIC_CONFIGURATION:
|
||||
return {
|
||||
...state,
|
||||
...action.config,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -22,8 +22,9 @@ import {
|
||||
import { createHistory } from 'coral-framework/services/history';
|
||||
import { createIntrospection } from 'coral-framework/services/introspection';
|
||||
import introspectionData from 'coral-framework/graphql/introspection.json';
|
||||
import auth from '../reducers/auth';
|
||||
import coreReducers from '../reducers';
|
||||
import { checkLogin } from '../actions/auth';
|
||||
import { setStaticConfiguration } from '../actions/static';
|
||||
|
||||
/**
|
||||
* getAuthToken returns the active auth token or null
|
||||
@@ -100,7 +101,8 @@ export async function createContext({
|
||||
token,
|
||||
});
|
||||
|
||||
let { LIVE_URI: liveUri } = getStaticConfiguration();
|
||||
const staticConfig = getStaticConfiguration();
|
||||
let { LIVE_URI: liveUri } = staticConfig;
|
||||
if (liveUri == null) {
|
||||
// The protocol must match the origin protocol, secure/insecure.
|
||||
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
@@ -163,7 +165,8 @@ export async function createContext({
|
||||
|
||||
// Create our redux store.
|
||||
const finalReducers = {
|
||||
authCore: auth,
|
||||
authCore: coreReducers.auth,
|
||||
static: coreReducers.static,
|
||||
...reducers,
|
||||
...plugins.getReducers(),
|
||||
};
|
||||
@@ -183,6 +186,7 @@ export async function createContext({
|
||||
[client.middleware(), apolloErrorReporter, createReduxEmitter(eventEmitter)]
|
||||
);
|
||||
|
||||
store.dispatch(setStaticConfiguration(staticConfig));
|
||||
store.dispatch(checkLogin());
|
||||
|
||||
// Run pre initialization.
|
||||
|
||||
Reference in New Issue
Block a user