about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaciek Baron <thebezet@gmail.com>2018-07-03 15:12:05 +0100
committerEugen Rochko <eugen@zeonfederated.com>2018-07-03 16:12:05 +0200
commitbbbe3ed6baec5758704ceda31f50182bcccea86c (patch)
treea0eede32010d3ec9726b779afcceba446f9c40b8
parent6d45f768a62cd36674dd595880f4999c12a244a1 (diff)
Allow the media modal to be closed by pressing back (#7934)
-rw-r--r--app/javascript/mastodon/features/ui/components/media_modal.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/javascript/mastodon/features/ui/components/media_modal.js b/app/javascript/mastodon/features/ui/components/media_modal.js
index f4d6b5c4e..c154da89a 100644
--- a/app/javascript/mastodon/features/ui/components/media_modal.js
+++ b/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 () {