diff --git a/platform/viewer/src/OHIFStandaloneViewer.js b/platform/viewer/src/OHIFStandaloneViewer.js deleted file mode 100644 index 9d0aedac1..000000000 --- a/platform/viewer/src/OHIFStandaloneViewer.js +++ /dev/null @@ -1,219 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { withRouter, matchPath } from 'react-router'; -import { Route, Switch } from 'react-router-dom'; -import { NProgress } from '@tanem/react-nprogress'; -import { CSSTransition } from 'react-transition-group'; -import { connect } from 'react-redux'; -import { ViewerbaseDragDropContext } from '@ohif/ui'; -import { SignoutCallbackComponent } from 'redux-oidc'; -import asyncComponent from './components/AsyncComponent.js'; -import * as RoutesUtil from './routes/routesUtil'; - -import NotFound from './routes/NotFound.js'; -import { Bar, Container } from './components/LoadingBar/'; -import './OHIFStandaloneViewer.css'; -import './variables.css'; -import './theme-tide.css'; -// Contexts -import AppContext from './context/AppContext'; -const CallbackPage = asyncComponent(() => - import(/* webpackChunkName: "CallbackPage" */ './routes/CallbackPage.js') -); - -class OHIFStandaloneViewer extends Component { - static contextType = AppContext; - state = { - isLoading: false, - }; - - static propTypes = { - history: PropTypes.object.isRequired, - user: PropTypes.object, - setContext: PropTypes.func, - userManager: PropTypes.object, - location: PropTypes.object, - }; - - componentDidMount() { - this.unlisten = this.props.history.listen((location, action) => { - if (this.props.setContext) { - this.props.setContext(window.location.pathname); - } - }); - } - - componentWillUnmount() { - this.unlisten(); - } - - render() { - const { user, userManager } = this.props; - const { appConfig = {} } = this.context; - const userNotLoggedIn = userManager && (!user || user.expired); - if (userNotLoggedIn) { - const pathname = this.props.location.pathname; - - if (pathname !== '/callback') { - sessionStorage.setItem('ohif-redirect-to', pathname); - } - - return ( - - - ( - console.log('Signout successful')} - errorCallback={error => { - console.warn(error); - console.warn('Signout failed'); - }} - /> - )} - /> - } - /> - { - const queryParams = new URLSearchParams( - this.props.location.search - ); - const iss = queryParams.get('iss'); - const loginHint = queryParams.get('login_hint'); - const targetLinkUri = queryParams.get('target_link_uri'); - const oidcAuthority = - appConfig.oidc !== null && appConfig.oidc[0].authority; - if (iss !== oidcAuthority) { - console.error( - 'iss of /login does not match the oidc authority' - ); - return null; - } - - userManager.removeUser().then(() => { - if (targetLinkUri !== null) { - sessionStorage.setItem( - 'ohif-redirect-to', - new URL(targetLinkUri).pathname - ); - } else { - sessionStorage.setItem('ohif-redirect-to', '/'); - } - - if (loginHint !== null) { - userManager.signinRedirect({ login_hint: loginHint }); - } else { - userManager.signinRedirect(); - } - }); - - return null; - }} - /> - { - userManager.getUser().then(user => { - if (user) { - userManager.signinSilent(); - } else { - userManager.signinRedirect(); - } - }); - - return null; - }} - /> - - ); - } - - /** - * Note: this approach for routing is caused by the conflict between - * react-transition-group and react-router's component. - * - * See http://reactcommunity.org/react-transition-group/with-react-router/ - */ - const routes = RoutesUtil.getRoutes(appConfig); - - const currentPath = this.props.location.pathname; - const noMatchingRoutes = !routes.find(r => - matchPath(currentPath, { - path: r.path, - exact: true, - }) - ); - - return ( - <> - - {({ isFinished, progress, animationDuration }) => ( - - - - )} - - - - {!noMatchingRoutes && - routes.map(({ path, Component }) => ( - - {({ match }) => ( - { - this.setState({ - isLoading: true, - }); - }} - onEntered={() => { - this.setState({ - isLoading: false, - }); - }} - > - {match === null ? ( - <> - ) : ( - - )} - - )} - - ))} - {noMatchingRoutes && } - - ); - } -} - -const mapStateToProps = state => { - return { - user: state.oidc.user, - }; -}; - -const ConnectedOHIFStandaloneViewer = connect( - mapStateToProps, - null -)(OHIFStandaloneViewer); - -export default ViewerbaseDragDropContext( - withRouter(ConnectedOHIFStandaloneViewer) -);