diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-07-13 15:45:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 15:45:21 +0200 |
commit | 82bc8e764798b74f475763136117592526d905fa (patch) | |
tree | f4d08fae970df4476065f04fe33d3e1aab266660 /app/javascript/flavours/glitch/components/modal_root.js | |
parent | ddf3f4cf85f0be6f221e68bda5944dd8a034ff91 (diff) | |
parent | e4270cb55a133f4cb93290ff88b3fd2a3aa9f536 (diff) |
Merge pull request #1566 from ClearlyClaire/glitch-soc/feature/modal-stack
Fix boost/fav confirmation modals closing media modal
Diffstat (limited to 'app/javascript/flavours/glitch/components/modal_root.js')
-rw-r--r-- | app/javascript/flavours/glitch/components/modal_root.js | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/app/javascript/flavours/glitch/components/modal_root.js b/app/javascript/flavours/glitch/components/modal_root.js index 913234d32..7b5a630e5 100644 --- a/app/javascript/flavours/glitch/components/modal_root.js +++ b/app/javascript/flavours/glitch/components/modal_root.js @@ -76,10 +76,13 @@ export default class ModalRoot extends React.PureComponent { this.activeElement = null; }).catch(console.error); - this.handleModalClose(); + this._handleModalClose(); } if (this.props.children && !prevProps.children) { - this.handleModalOpen(); + this._handleModalOpen(); + } + if (this.props.children) { + this._ensureHistoryBuffer(); } } @@ -88,22 +91,29 @@ export default class ModalRoot extends React.PureComponent { window.removeEventListener('keydown', this.handleKeyDown); } - handleModalClose () { + _handleModalOpen () { + this._modalHistoryKey = Date.now(); + this.unlistenHistory = this.history.listen((_, action) => { + if (action === 'POP') { + this.props.onClose(); + } + }); + } + + _handleModalClose () { this.unlistenHistory(); - const state = this.history.location.state; - if (state && state.mastodonModalOpen) { + const { state } = this.history.location; + if (state && state.mastodonModalKey === this._modalHistoryKey) { this.history.goBack(); } } - handleModalOpen () { - const history = this.history; - const state = {...history.location.state, mastodonModalOpen: true}; - history.push(history.location.pathname, state); - this.unlistenHistory = history.listen(() => { - this.props.onClose(); - }); + _ensureHistoryBuffer () { + const { pathname, state } = this.history.location; + if (!state || state.mastodonModalKey !== this._modalHistoryKey) { + this.history.push(pathname, { ...state, mastodonModalKey: this._modalHistoryKey }); + } } getSiblings = () => { |