ohif-viewer/src/OHIFStandaloneViewer.js

118 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-04-29 14:32:49 +02:00
import React, { Component } from 'react'
import PropTypes from 'prop-types'
2019-04-29 15:22:20 +02:00
// import asyncComponent from './components/AsyncComponent.js'
import IHEInvokeImageDisplay from './routes/IHEInvokeImageDisplay.js'
import ViewerRouting from './routes/ViewerRouting.js'
import StudyListRouting from './studylist/StudyListRouting.js'
import StandaloneRouting from './routes/StandaloneRouting.js'
import CallbackPage from './CallbackPage.js'
2019-04-29 14:32:49 +02:00
import { withRouter } from 'react-router'
import { Route, Switch } from 'react-router-dom'
import { connect } from 'react-redux'
import { ViewerbaseDragDropContext } from 'react-viewerbase'
2019-04-29 14:32:49 +02:00
import './OHIFStandaloneViewer.css'
import './variables.css'
import './theme-tide.css'
2019-04-29 14:32:49 +02:00
// Dynamic Import Routes (CodeSplitting)
2019-04-29 15:22:20 +02:00
// 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'))
2019-04-29 14:32:49 +02:00
//
const reload = () => window.location.reload()
class OHIFStandaloneViewer extends Component {
static propTypes = {
history: PropTypes.object.isRequired,
2019-04-29 14:32:49 +02:00
user: PropTypes.object,
}
componentDidMount() {
this.unlisten = this.props.history.listen((location, action) => {
if (this.props.setContext) {
2019-04-29 14:32:49 +02:00
this.props.setContext(window.location.pathname)
}
2019-04-29 14:32:49 +02:00
})
}
componentWillUnmount() {
2019-04-29 14:32:49 +02:00
this.unlisten()
}
render() {
2019-04-29 14:32:49 +02:00
const { user, userManager } = this.props
2019-04-29 14:32:49 +02:00
const userNotLoggedIn = userManager && (!user || user.expired)
if (userNotLoggedIn) {
2019-04-29 14:32:49 +02:00
const pathname = this.props.location.pathname
if (pathname !== '/callback') {
2019-04-29 14:32:49 +02:00
sessionStorage.setItem('ohif-redirect-to', pathname)
}
return (
<Switch>
<Route exact path="/silent-refresh.html" onEnter={reload} />
<Route exact path="/logout-redirect.html" onEnter={reload} />
<Route
path="/callback"
render={() => <CallbackPage userManager={userManager} />}
/>
<Route
component={() => {
2019-04-29 14:32:49 +02:00
userManager.signinRedirect()
2019-04-29 14:32:49 +02:00
return null
}}
/>
</Switch>
2019-04-29 14:32:49 +02:00
)
}
return (
<Switch>
<Route exact path="/silent-refresh.html" onEnter={reload} />
<Route exact path="/logout-redirect.html" onEnter={reload} />
2019-04-29 14:32:49 +02:00
<Route exact path="/studylist" component={StudyListRouting} />
<Route exact path="/" component={StudyListRouting} />
<Route exact path="/viewer" component={StandaloneRouting} />
<Route path="/viewer/:studyInstanceUids" component={ViewerRouting} />
<Route
path="/study/:studyInstanceUid/series/:seriesInstanceUids"
component={ViewerRouting}
/>
<Route
path="/IHEInvokeImageDisplay"
component={IHEInvokeImageDisplay}
/>
<Route render={() => <div> Sorry, this page does not exist. </div>} />
</Switch>
2019-04-29 14:32:49 +02:00
)
}
}
const mapStateToProps = state => {
return {
2019-04-29 14:32:49 +02:00
user: state.oidc.user,
}
}
const ConnectedOHIFStandaloneViewer = connect(
mapStateToProps,
null
2019-04-29 14:32:49 +02:00
)(OHIFStandaloneViewer)
export default ViewerbaseDragDropContext(
withRouter(ConnectedOHIFStandaloneViewer)
2019-04-29 14:32:49 +02:00
)