From aefd664db1ef46b24a6d9edc5ac55248e9082b0e Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Fri, 24 Jan 2020 16:36:11 -0600 Subject: [PATCH] Correct some modal repops (#11739) * fix(modals): correct some repops * fix(modals): also clean out "prev" * refactor(modals): hide in dismiss event --- website/client/src/app.vue | 19 +++++++++++++++++++ .../components/challenges/challengeModal.vue | 4 ++-- .../challenges/closeChallengeModal.vue | 4 +++- .../src/components/payments/sendGemsModal.vue | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/website/client/src/app.vue b/website/client/src/app.vue index e77925225e..eb3658d5d8 100644 --- a/website/client/src/app.vue +++ b/website/client/src/app.vue @@ -609,6 +609,25 @@ export default { if (modalBefore) this.$root.$emit('bv::show::modal', modalBefore, { fromRoot: true }); }); + + // Dismiss modal aggressively. Pass a modal ID to remove a modal instance from the stack + // (both the stack entry itself and its "prev" reference) so we don't reopen it + this.$root.$on('habitica::dismiss-modal', oldModal => { + if (!oldModal) return; + this.$root.$emit('bv::hide::modal', oldModal); + let removeIndex = this.$store.state.modalStack + .map(modal => modal.modalId) + .indexOf(oldModal); + if (removeIndex >= 0) { + this.$store.state.modalStack.splice(removeIndex, 1); + } + removeIndex = this.$store.state.modalStack + .map(modal => modal.prev) + .indexOf(oldModal); + if (removeIndex >= 0) { + delete this.$store.state.modalStack[removeIndex].prev; + } + }); }, validStack (modalStack) { const modalsThatCanShowTwice = ['profile']; diff --git a/website/client/src/components/challenges/challengeModal.vue b/website/client/src/components/challenges/challengeModal.vue index 39a78b4a3f..b2759cf737 100644 --- a/website/client/src/components/challenges/challengeModal.vue +++ b/website/client/src/components/challenges/challengeModal.vue @@ -592,7 +592,7 @@ export default { this.$emit('createChallenge', challenge); this.resetWorkingChallenge(); - this.$root.$emit('bv::hide::modal', 'challenge-modal'); + this.$root.$emit('habitica::dismiss-modal', 'challenge-modal'); this.$router.push(`/challenges/${challenge._id}`); }, async updateChallenge () { @@ -613,7 +613,7 @@ export default { const challenge = await this.$store.dispatch('challenges:updateChallenge', { challenge: challengeDetails }); this.$emit('updatedChallenge', { challenge }); this.resetWorkingChallenge(); - this.$root.$emit('bv::hide::modal', 'challenge-modal'); + this.$root.$emit('habitica::dismiss-modal', 'challenge-modal'); }, toggleCategorySelect () { this.showCategorySelect = !this.showCategorySelect; diff --git a/website/client/src/components/challenges/closeChallengeModal.vue b/website/client/src/components/challenges/closeChallengeModal.vue index c95d5defd5..f722797c3d 100644 --- a/website/client/src/components/challenges/closeChallengeModal.vue +++ b/website/client/src/components/challenges/closeChallengeModal.vue @@ -144,14 +144,16 @@ export default { challengeId: this.challengeId, winnerId: this.winner._id, }); + this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal'); this.$router.push('/challenges/myChallenges'); }, async deleteChallenge () { - if (!window.confirm('Are you sure you want to delete this challenge?')) return; + if (!window.confirm(this.$t('sureDelCha'))) return; this.challenge = await this.$store.dispatch('challenges:deleteChallenge', { challengeId: this.challengeId, prize: this.prize, }); + this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal'); this.$router.push('/challenges/myChallenges'); }, }, diff --git a/website/client/src/components/payments/sendGemsModal.vue b/website/client/src/components/payments/sendGemsModal.vue index cf16303504..4347afe3cf 100644 --- a/website/client/src/components/payments/sendGemsModal.vue +++ b/website/client/src/components/payments/sendGemsModal.vue @@ -294,7 +294,7 @@ export default { this.sendingInProgress = false; }, close () { - this.$root.$emit('bv::hide::modal', 'send-gems'); + this.$root.$emit('habitica::dismiss-modal', 'send-gems'); }, }, };