Correct some modal repops (#11739)

* fix(modals): correct some repops

* fix(modals): also clean out "prev"

* refactor(modals): hide in dismiss event
This commit is contained in:
Sabe Jones
2020-01-24 16:36:11 -06:00
committed by GitHub
parent b9d3d7f87a
commit aefd664db1
4 changed files with 25 additions and 4 deletions

View File

@@ -609,6 +609,25 @@ export default {
if (modalBefore) this.$root.$emit('bv::show::modal', modalBefore, { fromRoot: true }); 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) { validStack (modalStack) {
const modalsThatCanShowTwice = ['profile']; const modalsThatCanShowTwice = ['profile'];

View File

@@ -592,7 +592,7 @@ export default {
this.$emit('createChallenge', challenge); this.$emit('createChallenge', challenge);
this.resetWorkingChallenge(); this.resetWorkingChallenge();
this.$root.$emit('bv::hide::modal', 'challenge-modal'); this.$root.$emit('habitica::dismiss-modal', 'challenge-modal');
this.$router.push(`/challenges/${challenge._id}`); this.$router.push(`/challenges/${challenge._id}`);
}, },
async updateChallenge () { async updateChallenge () {
@@ -613,7 +613,7 @@ export default {
const challenge = await this.$store.dispatch('challenges:updateChallenge', { challenge: challengeDetails }); const challenge = await this.$store.dispatch('challenges:updateChallenge', { challenge: challengeDetails });
this.$emit('updatedChallenge', { challenge }); this.$emit('updatedChallenge', { challenge });
this.resetWorkingChallenge(); this.resetWorkingChallenge();
this.$root.$emit('bv::hide::modal', 'challenge-modal'); this.$root.$emit('habitica::dismiss-modal', 'challenge-modal');
}, },
toggleCategorySelect () { toggleCategorySelect () {
this.showCategorySelect = !this.showCategorySelect; this.showCategorySelect = !this.showCategorySelect;

View File

@@ -144,14 +144,16 @@ export default {
challengeId: this.challengeId, challengeId: this.challengeId,
winnerId: this.winner._id, winnerId: this.winner._id,
}); });
this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal');
this.$router.push('/challenges/myChallenges'); this.$router.push('/challenges/myChallenges');
}, },
async deleteChallenge () { 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', { this.challenge = await this.$store.dispatch('challenges:deleteChallenge', {
challengeId: this.challengeId, challengeId: this.challengeId,
prize: this.prize, prize: this.prize,
}); });
this.$root.$emit('habitica::dismiss-modal', 'close-challenge-modal');
this.$router.push('/challenges/myChallenges'); this.$router.push('/challenges/myChallenges');
}, },
}, },

View File

@@ -294,7 +294,7 @@ export default {
this.sendingInProgress = false; this.sendingInProgress = false;
}, },
close () { close () {
this.$root.$emit('bv::hide::modal', 'send-gems'); this.$root.$emit('habitica::dismiss-modal', 'send-gems');
}, },
}, },
}; };