From 09b98a701c88601c38179c2b4839c732ba604381 Mon Sep 17 00:00:00 2001 From: Anthony Bradley Date: Mon, 25 Jun 2018 17:11:05 +0100 Subject: [PATCH] Feature - don't reload the page on redirect (#41) --- js/components/header.js | 15 ++++----------- js/components/targetList.js | 13 ++++++------- js/containers/previewHolder.js | 34 ++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/js/components/header.js b/js/components/header.js index ecf570fae..1975499f8 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -8,6 +8,8 @@ import * as apiActions from '../actions/apiActions' import * as nglActions from '../actions/nglLoadActions' import { connect } from 'react-redux' import * as nglObjectTypes from '../components/nglObjectTypes' +import { withRouter } from 'react-router-dom' +import { Link } from 'react-router-dom' class Header extends React.Component { @@ -16,7 +18,6 @@ class Header extends React.Component { super(props) this.getTargetList = this.getTargetList.bind(this); this.selectTarget = this.selectTarget.bind(this); - this.clicker = this.clicker.bind(this); this.generateTargetObject = this.generateTargetObject.bind(this); } @@ -51,17 +52,9 @@ class Header extends React.Component { selectTarget(option) { - for(var key in this.props.target_id_list){ - if(this.props.target_id_list[key].title==option){ - this.props.setTargetOn(this.props.target_id_list[key].id); - break; - } - } + this.props.history.push("/viewer/react/preview/target/" + option) } - clicker() { - this.props.setAppOn("TINDSPECT"); - } render() { return - + {data.title} } @@ -106,4 +105,4 @@ const mapDispatchToProps = { setMoleculeList: apiActions.setMoleculeList, setObjectList: apiActions.setTargetIdList } -export default connect(mapStateToProps, mapDispatchToProps)(TargetList); +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(TargetList)); diff --git a/js/containers/previewHolder.js b/js/containers/previewHolder.js index ef660e4c6..48a1a6538 100644 --- a/js/containers/previewHolder.js +++ b/js/containers/previewHolder.js @@ -11,22 +11,32 @@ import MolGroupSlider from '../components/molGroupSlider' import SummaryView from '../components/summaryView'; import * as apiActions from '../actions/apiActions'; import fetch from 'cross-fetch'; +import { withRouter } from 'react-router-dom' + class Preview extends Component { constructor(props) { super(props) - } - - - componentDidMount(){ - var target = this.props.match.params.target; - // Get from the REST API - fetch(window.location.protocol + "//" + window.location.host+"/api/targets/?title="+target) - .then(response => response.json()) - // Set the target id from the json - .then(json => this.props.setTargetOn(json["results"][0].id)); - } + this.updateTarget = this.updateTarget.bind(this); + } + + updateTarget(){ + var target = this.props.match.params.target; + // Get from the REST API + fetch(window.location.protocol + "//" + window.location.host+"/api/targets/?title="+target) + .then(response => response.json()) + // Set the target id from the josn + .then(json => this.props.setTargetOn(json["results"][0].id)); + } + componentDidMount() { + this.updateTarget() + } + + componentDidUpdate(){ + this.updateTarget() + } + render() { return ( @@ -58,4 +68,4 @@ const mapDispatchToProps = { } -export default connect(mapStateToProps, mapDispatchToProps)(Preview) \ No newline at end of file +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Preview)) \ No newline at end of file