Check if router is injected in media modal (#7941)

master
Maciek Baron 6 years ago committed by Eugen Rochko
parent 9dc413b025
commit f3af1a96a8
  1. 4
      app/javascript/mastodon/features/ui/components/media_modal.js

@ -67,21 +67,25 @@ export default class MediaModal extends ImmutablePureComponent {
componentDidMount () {
window.addEventListener('keyup', this.handleKeyUp, false);
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);
if (this.context.router) {
this.unlistenHistory();
if (this.context.router.history.location.state === previewState) {
this.context.router.history.goBack();
}
}
}
getIndex () {
return this.state.index !== null ? this.state.index : this.props.index;

Loading…
Cancel
Save