Fix Modal Stack - reopening modals (#10493)

* use fallback target.id - only scroll modal content (not the page)

* fix lint

* debug information

* add snackbar onClick callback - use notification instead of modal for joined-challenge

* revert console.log / fix lint
This commit is contained in:
negue
2018-07-20 22:50:40 +02:00
committed by Sabe Jones
parent b7a46637d5
commit 7b562c45cf
5 changed files with 35 additions and 9 deletions

View File

@@ -105,7 +105,7 @@ div
@import '~client/assets/scss/colors.scss'; @import '~client/assets/scss/colors.scss';
/* @TODO: The modal-open class is not being removed. Let's try this for now */ /* @TODO: The modal-open class is not being removed. Let's try this for now */
.modal, .modal-open { .modal {
overflow-y: scroll !important; overflow-y: scroll !important;
} }
@@ -499,8 +499,16 @@ export default {
}); });
this.$root.$on('bv::modal::hidden', (bvEvent) => { this.$root.$on('bv::modal::hidden', (bvEvent) => {
const modalId = bvEvent.target && bvEvent.target.id; let modalId = bvEvent.target && bvEvent.target.id;
if (!modalId) return;
// 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.modalStack; const modalStack = this.$store.state.modalStack;
@@ -517,6 +525,7 @@ export default {
// Get previous modal // Get previous modal
const modalBefore = modalOnTop ? modalOnTop.prev : undefined; const modalBefore = modalOnTop ? modalOnTop.prev : undefined;
if (modalBefore) this.$root.$emit('bv::show::modal', modalBefore, {fromRoot: true}); if (modalBefore) this.$root.$emit('bv::show::modal', modalBefore, {fromRoot: true});
}); });
}, },

View File

@@ -485,7 +485,9 @@ export default {
break; break;
case 'CHALLENGE_JOINED_ACHIEVEMENT': case 'CHALLENGE_JOINED_ACHIEVEMENT':
this.playSound('Achievement_Unlocked'); this.playSound('Achievement_Unlocked');
this.text(`${this.$t('achievement')}: ${this.$t('joinedChallenge')}`, () => {
this.$root.$emit('bv::show::modal', 'joined-challenge'); this.$root.$emit('bv::show::modal', 'joined-challenge');
}, false);
break; break;
case 'INVITED_FRIEND_ACHIEVEMENT': case 'INVITED_FRIEND_ACHIEVEMENT':
this.playSound('Achievement_Unlocked'); this.playSound('Achievement_Unlocked');

View File

@@ -1,6 +1,6 @@
<template lang="pug"> <template lang="pug">
transition(name="fade") transition(name="fade")
.notification.callout.animated(:class="classes", v-if='show', @click='show = false') .notification.callout.animated(:class="classes", v-if='show', @click='handleOnClick()')
.row(v-if='notification.type === "error"') .row(v-if='notification.type === "error"')
.text.col-12 .text.col-12
div(v-html='notification.text') div(v-html='notification.text')
@@ -146,6 +146,15 @@ export default {
beforeDestroy () { beforeDestroy () {
clearTimeout(this.timer); clearTimeout(this.timer);
}, },
methods: {
handleOnClick () {
if (typeof this.notification.onClick === 'function') {
this.notification.onClick();
}
this.show = false;
},
},
watch: { watch: {
show () { show () {
this.$store.dispatch('snackbars:remove', this.notification); this.$store.dispatch('snackbars:remove', this.notification);

View File

@@ -56,9 +56,9 @@ export default {
streak (val) { streak (val) {
this.notify(`${val}`, 'streak'); this.notify(`${val}`, 'streak');
}, },
text (val, onClick) { text (val, onClick, timeout) {
if (!val) return; if (!val) return;
this.notify(val, 'info', null, null, onClick); this.notify(val, 'info', null, null, onClick, timeout);
}, },
sign (number) { sign (number) {
return getSign(number); return getSign(number);
@@ -66,14 +66,19 @@ export default {
round (number, nDigits) { round (number, nDigits) {
return round(number, nDigits); return round(number, nDigits);
}, },
notify (html, type, icon, sign) { notify (html, type, icon, sign, onClick, timeout) {
if (typeof timeout === 'undefined') {
timeout = true;
}
this.$store.dispatch('snackbars:add', { this.$store.dispatch('snackbars:add', {
title: '', title: '',
text: html, text: html,
type, type,
icon, icon,
sign, sign,
timeout: true, onClick,
timeout,
}); });
}, },
}, },

View File

@@ -1,4 +1,5 @@
{ {
"achievement": "Achievement",
"share": "Share", "share": "Share",
"onwards": "Onwards!", "onwards": "Onwards!",
"levelup": "By accomplishing your real life goals, you leveled up and are now fully healed!", "levelup": "By accomplishing your real life goals, you leveled up and are now fully healed!",