Skip to content

Commit

Permalink
stop exiting a modal using history.back()
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 30, 2018
1 parent 81a4277 commit f59bcfe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
socket(public_key, {
element: '#socket4',
router_mode: 'history',
mode: 'enquiry',
mode: 'enquiry-modal',
api_root: api_root,
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/contractors/ConModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ConModal extends Component {
}
const {contractor, contractor_extra} = _con
return (
<Modal history={this.props.history} title={contractor.name}>
<Modal history={this.props.history} title={contractor.name} last_url={this.props.last_url}>
<div className="tcs-body">
<div className="tcs-extra">
<img src={contractor.photo} alt={contractor.name}/>
Expand Down
6 changes: 5 additions & 1 deletion src/components/contractors/Contractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Contractors extends Component {
more_pages: false,
subjects: [],
selected_subject: null,
last_url: null,
}
this.update_contractors = this.update_contractors.bind(this)
this.get_contractor_details = this.get_contractor_details.bind(this)
Expand Down Expand Up @@ -52,7 +53,9 @@ class Contractors extends Component {
}

subject_change (selected_subject) {
this.props.history.push(this.subject_url(selected_subject))
const url = this.subject_url(selected_subject)
this.props.history.push(url)
this.setState({last_url: url})
this.update_contractors(selected_subject)
}

Expand Down Expand Up @@ -135,6 +138,7 @@ class Contractors extends Component {
</If>
<Route path={this.props.root.url(':id(\\d+):_extra')} render={props => (
<ConModal id={props.match.params.id}
last_url={this.state.last_url}
contractors={this.state.contractors}
got_contractors={this.state.got_contractors}
get_contractor_details={this.get_contractor_details}
Expand Down
4 changes: 3 additions & 1 deletion src/components/shared/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Modal extends Component {

close () {
this.setState({show: false})
setTimeout(() => this.props.history.goBack(), 200)
const h = this.props.history
const next_url = this.props.last_url ? this.props.last_url : h.location.pathname.replace(/\/[^/]+$/, '')
setTimeout(() => h.push(next_url), 200)
}

render () {
Expand Down

0 comments on commit f59bcfe

Please sign in to comment.