From 19aa4b23cd34c8cf3d17254762f7127311bfcf62 Mon Sep 17 00:00:00 2001 From: dannyrb Date: Mon, 29 Apr 2019 08:32:49 -0400 Subject: [PATCH] Codesplit at route level --- src/OHIFStandaloneViewer.js | 82 ++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/src/OHIFStandaloneViewer.js b/src/OHIFStandaloneViewer.js index a58a39b40..393a63c4e 100644 --- a/src/OHIFStandaloneViewer.js +++ b/src/OHIFStandaloneViewer.js @@ -1,48 +1,58 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { withRouter } from 'react-router'; -import { Route, Switch } from 'react-router-dom'; -import { connect } from 'react-redux'; -import { ViewerbaseDragDropContext } from 'react-viewerbase'; -import ViewerRouting from './routes/ViewerRouting.js'; -import StudyListRouting from './studylist/StudyListRouting.js' -import StandaloneRouting from './routes/StandaloneRouting.js'; -import IHEInvokeImageDisplay from './routes/IHEInvokeImageDisplay.js'; -import CallbackPage from './CallbackPage.js'; +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import asyncComponent from './components/AsyncComponent.js' +import { withRouter } from 'react-router' +import { Route, Switch } from 'react-router-dom' +import { connect } from 'react-redux' +import { ViewerbaseDragDropContext } from 'react-viewerbase' -import './OHIFStandaloneViewer.css'; -import './variables.css'; -import './theme-tide.css'; +import './OHIFStandaloneViewer.css' +import './variables.css' +import './theme-tide.css' -const reload = () => window.location.reload(); +// Dynamic Import Routes (CodeSplitting) +const IHEInvokeImageDisplay = asyncComponent(() => + import('./routes/IHEInvokeImageDisplay.js') +) +const ViewerRouting = asyncComponent(() => import('./routes/ViewerRouting.js')) +const StudyListRouting = asyncComponent(() => + import('./studylist/StudyListRouting.js') +) +const StandaloneRouting = asyncComponent(() => + import('./routes/StandaloneRouting.js') +) +const CallbackPage = asyncComponent(() => import('./CallbackPage.js')) +// + +const reload = () => window.location.reload() class OHIFStandaloneViewer extends Component { static propTypes = { history: PropTypes.object.isRequired, - user: PropTypes.object - }; + user: PropTypes.object, + } componentDidMount() { this.unlisten = this.props.history.listen((location, action) => { if (this.props.setContext) { - this.props.setContext(window.location.pathname); + this.props.setContext(window.location.pathname) } - }); + }) } componentWillUnmount() { - this.unlisten(); + this.unlisten() } render() { - const { user, userManager } = this.props; + const { user, userManager } = this.props - const userNotLoggedIn = userManager && (!user || user.expired); + const userNotLoggedIn = userManager && (!user || user.expired) if (userNotLoggedIn) { - const pathname = this.props.location.pathname; + const pathname = this.props.location.pathname if (pathname !== '/callback') { - sessionStorage.setItem('ohif-redirect-to', pathname); + sessionStorage.setItem('ohif-redirect-to', pathname) } return ( @@ -55,24 +65,20 @@ class OHIFStandaloneViewer extends Component { /> { - userManager.signinRedirect(); + userManager.signinRedirect() - return null; + return null }} /> - ); + ) } return ( - + @@ -86,21 +92,21 @@ class OHIFStandaloneViewer extends Component { />
Sorry, this page does not exist.
} />
- ); + ) } } const mapStateToProps = state => { return { - user: state.oidc.user - }; -}; + user: state.oidc.user, + } +} const ConnectedOHIFStandaloneViewer = connect( mapStateToProps, null -)(OHIFStandaloneViewer); +)(OHIFStandaloneViewer) export default ViewerbaseDragDropContext( withRouter(ConnectedOHIFStandaloneViewer) -); +)