Skip to content

Commit

Permalink
Fix conditional rendering of DevTools
Browse files Browse the repository at this point in the history
  • Loading branch information
JDRomano2 committed May 20, 2018
1 parent ae8b17f commit 01eb285
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 75 deletions.
39 changes: 32 additions & 7 deletions index/components/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Switch, Route } from 'react-router';

const App = ({ children }) =>
<div id="venomkb-app">
{ children }
</div>;
import Home from './Home';
import About from './About';
import AboutFeatures from './AboutFeatures';
import AboutVenomseq from './AboutVenomseq';
import AboutOntology from './AboutOntology';
import AboutVenoms from './AboutVenoms';
import AboutApi from './AboutApi';
import Contact from './Contact';
import Publications from './Publications';
import Download from './Download';
import NotFound from './NotFound';

App.propTypes = {
children: PropTypes.object
};
import DataContainer from '../containers/DataContainer';
import DataDetailContainer from '../containers/DataDetailContainer';

const App = () => (
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/about/features" component={AboutFeatures} />
<Route path="/about/venomseq" component={AboutVenomseq} />
<Route path="/about/ontology" component={AboutOntology} />
<Route path="/about/whyvenoms" component={AboutVenoms} />
<Route path="/about/api" components={AboutApi} />
<Route path="/contact" component={Contact} />
<Route path="/publications" component={Publications} />
<Route path="/data" component={DataContainer} />
<Route path="/download" component={Download} />
<Route path="/:index" component={DataDetailContainer} />
<Route path="*" component={NotFound} />
</Switch>
);

export default App;
2 changes: 1 addition & 1 deletion index/components/DataBasicView.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DataBasicView extends Component {
);
case 'S':
return (
<div style={{'margin-top': '10px'}}>
<div style={{'marginTop': '10px'}}>
<Col xs={12} md={7}>
<h1>{name}</h1>
Annotation score: <img
Expand Down
7 changes: 4 additions & 3 deletions index/containers/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { createDevTools } from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';
import DockMonitor from 'redux-devtools-dock-monitor';
import Dispatcher from 'redux-devtools-dispatch';
// import Dispatcher from 'redux-devtools-dispatch';
import MultipleMonitors from 'redux-devtools-multiple-monitors';

export default createDevTools(
Expand All @@ -11,9 +11,10 @@ export default createDevTools(
changePositionKey="ctrl-w"
defaultSize={0.25}
defaultIsVisible={false}>
<MultipleMonitors>
{/* <MultipleMonitors>
<LogMonitor />
<Dispatcher />
</MultipleMonitors>
</MultipleMonitors> */}
<LogMonitor />
</DockMonitor>
);
27 changes: 27 additions & 0 deletions index/containers/Root.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import createHistory from 'history/createBrowserHistory';
import { ConnectedRouter } from 'react-router-redux';


import App from '../components/App';
import DevTools from './DevTools';

const history = createHistory();

export default class Root extends Component {
render() {
const { store } = this.props;

return (
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<App/>
<DevTools/>
</div>
</ConnectedRouter>
</Provider>
)
}
}
5 changes: 5 additions & 0 deletions index/containers/Root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (process.env.NODE_ENV === 'production') {
module.exports = require('./Root.prod');
} else {
module.exports = require('./Root.dev');
}
22 changes: 22 additions & 0 deletions index/containers/Root.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import createHistory from 'history/createBrowserHistory';
import { ConnectedRouter } from 'react-router-redux';

import App from '../components/App';

const history = createHistory();

export default class Root extends Component {
render() {
const { store } = this.props;

return (
<Provider store={store}>
<ConnectedRouter history={history}>
<App/>
</ConnectedRouter>
</Provider>
)
}
}
24 changes: 12 additions & 12 deletions index/store/configureStore.dev.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { persistState } from 'redux-devtools';
import rootReducer from '../reducers';
import DevTools from '../containers/DevTools';

export default function configureStore(initialState) {
// const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancer = compose(
applyMiddleware(thunkMiddleware),
DevTools.instrument()
);
// middleware
import thunkMiddleware from 'redux-thunk'; // thunk allows reducers to return functions instead of objects

console.log("Calling configureStore.dev.js");

const store = createStore(
rootReducer,
initialState,
enhancer
);
const enhancer = compose(
applyMiddleware(thunkMiddleware),
DevTools.instrument()
);

export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState, enhancer);

return store;
}
16 changes: 10 additions & 6 deletions index/store/configureStore.prod.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { createStore } from 'redux';
import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from '../reducers';

// middleware
import thunkMiddleware from 'redux-thunk';

console.log("Calling configureStore.prod.js");

const enhancer = applyMiddleware(thunkMiddleware);

export default function configureStore(initialState) {
return createStore(
rootReducer,
initialState
);
}
return createStore(rootReducer, initialState, enhancer);
};
48 changes: 2 additions & 46 deletions venomkb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import ReactDOM from 'react-dom';

import { Switch, Route } from 'react-router';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'react-router-redux';
// import DevTools from './index/containers/DevTools';
import createHistory from 'history/createBrowserHistory';
import configureStore from './index/store/configureStore';

// handle api calls from within app
Expand All @@ -17,40 +14,7 @@ import 'react-table/react-table.css';
import './index/styles/venomkb.css';
import './index/img/images';

// import App from './index/components/App';
import Home from './index/components/Home';
import About from './index/components/About';
import AboutFeatures from './index/components/AboutFeatures';
import AboutVenomseq from './index/components/AboutVenomseq';
import AboutOntology from './index/components/AboutOntology';
import AboutVenoms from './index/components/AboutVenoms';
import AboutApi from './index/components/AboutApi';
import Contact from './index/components/Contact';
import Publications from './index/components/Publications';
import Download from './index/components/Download';
import NotFound from './index/components/NotFound';

import DataContainer from './index/containers/DataContainer';
import DataDetailContainer from './index/containers/DataDetailContainer';
import DevTools from './index/containers/DevTools';

const App = () => (
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/about/features" component={AboutFeatures} />
<Route path="/about/venomseq" component={AboutVenomseq} />
<Route path="/about/ontology" component={AboutOntology} />
<Route path="/about/whyvenoms" component={AboutVenoms} />
<Route path="/about/api" components={AboutApi} />
<Route path="/contact" component={Contact} />
<Route path="/publications" component={Publications} />
<Route path="/data" component={DataContainer} />
<Route path="/download" component={Download} />
<Route path="/:index" component={DataDetailContainer} />
<Route path="*" component={NotFound} />
</Switch>
);
import Root from './index/containers/Root';

getDbIndex().then((indexData) => {
const species = indexData.index.filter( (i) => {
Expand Down Expand Up @@ -86,17 +50,9 @@ getDbIndex().then((indexData) => {
index
}
});
const history = createHistory();

ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<App/>
<DevTools/>
</div>
</ConnectedRouter>
</Provider>,
<Root store={store} />,
document.getElementById('venomkb_root')
);
});

0 comments on commit 01eb285

Please sign in to comment.