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 });
});
// 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'];