Browse Source

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

pull/4/head
Maciek Baron 5 years ago
committed by Eugen Rochko
parent
commit
f3af1a96a8
1 changed files with 12 additions and 8 deletions
  1. +12
    -8
      app/javascript/mastodon/features/ui/components/media_modal.js

+ 12
- 8
app/javascript/mastodon/features/ui/components/media_modal.js View File

@ -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();
}
}
}

Loading…
Cancel
Save