瀏覽代碼

Allow the media modal to be closed by pressing back (#7934)

master
Maciek Baron 5 年之前
committed by Eugen Rochko
父節點
當前提交
bbbe3ed6ba
共有 1 個檔案被更改,包括 16 行新增0 行删除
  1. +16
    -0
      app/javascript/mastodon/features/ui/components/media_modal.js

+ 16
- 0
app/javascript/mastodon/features/ui/components/media_modal.js 查看文件

@@ -16,6 +16,8 @@ const messages = defineMessages({
next: { id: 'lightbox.next', defaultMessage: 'Next' },
});

const previewState = 'previewMediaModal';

@injectIntl
export default class MediaModal extends ImmutablePureComponent {

@@ -26,6 +28,10 @@ export default class MediaModal extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};

static contextTypes = {
router: PropTypes.object,
};

state = {
index: null,
navigationHidden: false,
@@ -61,10 +67,20 @@ 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();
});
}

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

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

getIndex () {


Loading…
取消
儲存