Skip to content

Commit f59bcfe

Browse files
committed
stop exiting a modal using history.back()
1 parent 81a4277 commit f59bcfe

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
socket(public_key, {
6767
element: '#socket4',
6868
router_mode: 'history',
69-
mode: 'enquiry',
69+
mode: 'enquiry-modal',
7070
api_root: api_root,
7171
})
7272
</script>

src/components/contractors/ConModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ConModal extends Component {
5252
}
5353
const {contractor, contractor_extra} = _con
5454
return (
55-
<Modal history={this.props.history} title={contractor.name}>
55+
<Modal history={this.props.history} title={contractor.name} last_url={this.props.last_url}>
5656
<div className="tcs-body">
5757
<div className="tcs-extra">
5858
<img src={contractor.photo} alt={contractor.name}/>

src/components/contractors/Contractors.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Contractors extends Component {
1616
more_pages: false,
1717
subjects: [],
1818
selected_subject: null,
19+
last_url: null,
1920
}
2021
this.update_contractors = this.update_contractors.bind(this)
2122
this.get_contractor_details = this.get_contractor_details.bind(this)
@@ -52,7 +53,9 @@ class Contractors extends Component {
5253
}
5354

5455
subject_change (selected_subject) {
55-
this.props.history.push(this.subject_url(selected_subject))
56+
const url = this.subject_url(selected_subject)
57+
this.props.history.push(url)
58+
this.setState({last_url: url})
5659
this.update_contractors(selected_subject)
5760
}
5861

@@ -135,6 +138,7 @@ class Contractors extends Component {
135138
</If>
136139
<Route path={this.props.root.url(':id(\\d+):_extra')} render={props => (
137140
<ConModal id={props.match.params.id}
141+
last_url={this.state.last_url}
138142
contractors={this.state.contractors}
139143
got_contractors={this.state.got_contractors}
140144
get_contractor_details={this.get_contractor_details}

src/components/shared/Modal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Modal extends Component {
3737

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

4345
render () {

0 commit comments

Comments
 (0)