diff --git a/website/client/src/app.vue b/website/client/src/app.vue index 5f9a888b35..97061e1fff 100644 --- a/website/client/src/app.vue +++ b/website/client/src/app.vue @@ -513,13 +513,9 @@ export default { } else { this.hideLoadingScreen(); } - - this.initializeModalStack(); }, beforeDestroy () { this.$root.$off('playSound'); - this.$root.$off('bv::modal::hidden'); - this.$root.$off('bv::show::modal'); this.$root.$off('buyModal::showItem'); this.$root.$off('selectMembersModal::showItem'); }, @@ -549,112 +545,6 @@ export default { this.$store.dispatch('auth:logout', { redirectToLogin: true }); return true; }, - initializeModalStack () { - // Manage modals - this.$root.$on('bv::show::modal', (modalId, data = {}) => { - if (data.fromRoot) return; - const { modalStack } = this.$store.state; - - this.trackGemPurchase(modalId, data); - - // Add new modal to the stack - const prev = modalStack[modalStack.length - 1]; - const prevId = prev ? prev.modalId : undefined; - modalStack.push({ modalId, prev: prevId }); - }); - - this.$root.$on('bv::modal::hidden', bvEvent => { - let modalId = bvEvent.target && bvEvent.target.id; - - // sometimes the target isn't passed to the hidden event, fallback is the vueTarget - if (!modalId) { - modalId = bvEvent.vueTarget && bvEvent.vueTarget.id; - } - - if (!modalId) { - return; - } - - const { modalStack } = this.$store.state; - - const modalOnTop = modalStack[modalStack.length - 1]; - - // Check for invalid modal. Event systems can send multiples - if (!this.validStack(modalStack)) return; - - // If we are moving forward - if (modalOnTop && modalOnTop.prev === modalId) return; - - // Remove modal from stack - this.$store.state.modalStack.pop(); - - // Get previous modal - const modalBefore = modalOnTop ? modalOnTop.prev : undefined; - - 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']; - const modalCount = {}; - const prevAndCurrent = 2; - - for (const current of modalStack) { - if (!modalCount[current.modalId]) modalCount[current.modalId] = 0; - modalCount[current.modalId] += 1; - if ( - modalCount[current.modalId] > prevAndCurrent - && modalsThatCanShowTwice.indexOf(current.modalId) === -1 - ) { - this.$store.state.modalStack = []; - return false; - } - - if (!current.prev) continue; // eslint-disable-line - if (!modalCount[current.prev]) modalCount[current.prev] = 0; - modalCount[current.prev] += 1; - if ( - modalCount[current.prev] > prevAndCurrent - && modalsThatCanShowTwice.indexOf(current.prev) === -1 - ) { - this.$store.state.modalStack = []; - return false; - } - } - - return true; - }, - trackGemPurchase (modalId, data) { - // Track opening of gems modal unless it's been already tracked - // For example the gems button in the menu already tracks the event by itself - if (modalId === 'buy-gems' && data.alreadyTracked !== true) { - Analytics.track({ - hitType: 'event', - eventCategory: 'button', - eventAction: 'click', - eventLabel: 'Gems > Wallet', - }); - } - }, itemSelected (item) { this.selectedItemToBuy = item; }, diff --git a/website/client/src/components/achievements/firstDrops.vue b/website/client/src/components/achievements/firstDrops.vue index 7aeb7f0569..4a340ef664 100644 --- a/website/client/src/components/achievements/firstDrops.vue +++ b/website/client/src/components/achievements/firstDrops.vue @@ -126,7 +126,7 @@ export default { egg: '', hatchingPotion: '', }; - this.$root.$emit('habitica::dismiss-modal', 'first-drops'); + this.$root.$emit('bv::hide::modal', 'first-drops'); }, toInventory () { this.$router.push('/inventory/items'); diff --git a/website/client/src/components/challenges/challengeModal.vue b/website/client/src/components/challenges/challengeModal.vue index 2db570b114..282e9367c4 100644 --- a/website/client/src/components/challenges/challengeModal.vue +++ b/website/client/src/components/challenges/challengeModal.vue @@ -607,7 +607,7 @@ export default { this.$emit('createChallenge', challenge); this.resetWorkingChallenge(); - this.$root.$emit('habitica::dismiss-modal', 'challenge-modal'); + this.$root.$emit('bv::hide::modal', 'challenge-modal'); this.$router.push(`/challenges/${challenge._id}`); }, async updateChallenge () { @@ -628,7 +628,7 @@ export default { const challenge = await this.$store.dispatch('challenges:updateChallenge', { challenge: challengeDetails }); this.$emit('updatedChallenge', { challenge }); this.resetWorkingChallenge(); - this.$root.$emit('habitica::dismiss-modal', 'challenge-modal'); + this.$root.$emit('bv::hide::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 f722797c3d..a7f43455bf 100644 --- a/website/client/src/components/challenges/closeChallengeModal.vue +++ b/website/client/src/components/challenges/closeChallengeModal.vue @@ -144,7 +144,7 @@ export default { challengeId: this.challengeId, winnerId: this.winner._id, }); - this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal'); + this.$root.$emit('bv::hide::modal', 'close-challenge-modal'); this.$router.push('/challenges/myChallenges'); }, async deleteChallenge () { @@ -153,7 +153,7 @@ export default { challengeId: this.challengeId, prize: this.prize, }); - this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal'); + this.$root.$emit('bv::hide::modal', 'close-challenge-modal'); this.$router.push('/challenges/myChallenges'); }, }, diff --git a/website/client/src/components/payments/buyGemsModal.vue b/website/client/src/components/payments/buyGemsModal.vue index 6aea148462..fa1ab47486 100644 --- a/website/client/src/components/payments/buyGemsModal.vue +++ b/website/client/src/components/payments/buyGemsModal.vue @@ -295,6 +295,7 @@