Skip to content

Commit

Permalink
Check if router is injected in media modal (mastodon#7941)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciekBaron authored and Gargron committed Jul 4, 2018
1 parent 9dc413b commit f3af1a9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/javascript/mastodon/features/ui/components/media_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ export default class MediaModal extends ImmutablePureComponent {

componentDidMount () {
window.addEventListener('keyup', this.handleKeyUp, false);
const history = this.context.router.history;
history.push(history.location.pathname, previewState);
this.unlistenHistory = history.listen(() => {
this.props.onClose();
});
if (this.context.router) {
const history = this.context.router.history;
history.push(history.location.pathname, previewState);
this.unlistenHistory = history.listen(() => {
this.props.onClose();
});
}
}

componentWillUnmount () {
window.removeEventListener('keyup', this.handleKeyUp);
this.unlistenHistory();
if (this.context.router) {
this.unlistenHistory();

if (this.context.router.history.location.state === previewState) {
this.context.router.history.goBack();
if (this.context.router.history.location.state === previewState) {
this.context.router.history.goBack();
}
}
}

Expand Down

0 comments on commit f3af1a9

Please sign in to comment.