mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
move modals to notifications (to open the modals)
This commit is contained in:
@@ -87,6 +87,7 @@ div
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import throttle from 'lodash/throttle';
|
import throttle from 'lodash/throttle';
|
||||||
|
import debounce from 'lodash/debounce';
|
||||||
|
|
||||||
import { shouldDo } from '../../common/script/cron';
|
import { shouldDo } from '../../common/script/cron';
|
||||||
import { mapState } from 'client/libs/store';
|
import { mapState } from 'client/libs/store';
|
||||||
@@ -117,6 +118,44 @@ import ultimateGear from './achievements/ultimateGear';
|
|||||||
import wonChallenge from './achievements/wonChallenge';
|
import wonChallenge from './achievements/wonChallenge';
|
||||||
import loginIncentives from './achievements/login-incentives';
|
import loginIncentives from './achievements/login-incentives';
|
||||||
|
|
||||||
|
const NOTIFICATIONS = {
|
||||||
|
CHALLENGE_JOINED_ACHIEVEMENT: {
|
||||||
|
achievement: true,
|
||||||
|
label: ($t) => `${$t('achievement')}: ${$t('joinedChallenge')}`,
|
||||||
|
modalId: 'joined-challenge',
|
||||||
|
},
|
||||||
|
ULTIMATE_GEAR_ACHIEVEMENT: {
|
||||||
|
achievement: true,
|
||||||
|
label: ($t) => `${$t('achievement')}: ${$t('gearAchievement')}`,
|
||||||
|
modalId: 'ultimate-gear',
|
||||||
|
},
|
||||||
|
REBIRTH_ACHIEVEMENT: {
|
||||||
|
label: ($t) => `${$t('achievement')}: ${$t('rebirthBegan')}`,
|
||||||
|
achievement: true,
|
||||||
|
modalId: 'rebirth',
|
||||||
|
},
|
||||||
|
GUILD_JOINED_ACHIEVEMENT: {
|
||||||
|
label: ($t) => `${$t('achievement')}: ${$t('joinedGuild')}`,
|
||||||
|
achievement: true,
|
||||||
|
modalId: 'joined-guild',
|
||||||
|
},
|
||||||
|
INVITED_FRIEND_ACHIEVEMENT: {
|
||||||
|
achievement: true,
|
||||||
|
label: ($t) => `${$t('achievement')}: ${$t('invitedFriend')}`,
|
||||||
|
modalId: 'invited-friend',
|
||||||
|
},
|
||||||
|
NEW_CONTRIBUTOR_LEVEL: {
|
||||||
|
achievement: true,
|
||||||
|
label: ($t) => $t('modalContribAchievement'),
|
||||||
|
modalId: 'contributor',
|
||||||
|
},
|
||||||
|
DEATH: {
|
||||||
|
sound: 'Death',
|
||||||
|
label: ($t) => $t('lostAllHealth'),
|
||||||
|
modalId: 'death',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [notifications, guide],
|
mixins: [notifications, guide],
|
||||||
components: {
|
components: {
|
||||||
@@ -206,8 +245,8 @@ export default {
|
|||||||
userHp (after, before) {
|
userHp (after, before) {
|
||||||
if (this.user.needsCron) return;
|
if (this.user.needsCron) return;
|
||||||
if (after <= 0) {
|
if (after <= 0) {
|
||||||
this.playSound('Death');
|
alert('userHp');
|
||||||
this.$root.$emit('bv::show::modal', 'death');
|
this.showNotificationWithModal('DEATH');
|
||||||
// @TODO: {keyboard:false, backdrop:'static'}
|
// @TODO: {keyboard:false, backdrop:'static'}
|
||||||
} else if (after <= 30 && !this.user.flags.warnedLowHealth) {
|
} else if (after <= 30 && !this.user.flags.warnedLowHealth) {
|
||||||
this.$root.$emit('bv::show::modal', 'low-health');
|
this.$root.$emit('bv::show::modal', 'low-health');
|
||||||
@@ -282,7 +321,7 @@ export default {
|
|||||||
this.$store.dispatch('user:fetch'),
|
this.$store.dispatch('user:fetch'),
|
||||||
this.$store.dispatch('tasks:fetchUserTasks'),
|
this.$store.dispatch('tasks:fetchUserTasks'),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
this.checkUserAchievements();
|
this.debounceCheckUserAchievements();
|
||||||
|
|
||||||
// @TODO: This is a timeout to ensure dom is loaded
|
// @TODO: This is a timeout to ensure dom is loaded
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
@@ -307,6 +346,30 @@ export default {
|
|||||||
document.removeEventListener('keydown', this.checkNextCron);
|
document.removeEventListener('keydown', this.checkNextCron);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
showNotificationWithModal (type, forceToModal) {
|
||||||
|
const config = NOTIFICATIONS[type];
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.achievement) {
|
||||||
|
this.playSound('Achievement_Unlocked');
|
||||||
|
} else if (config.sound) {
|
||||||
|
this.playSound(config.sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forceToModal) {
|
||||||
|
this.$root.$emit('bv::show::modal', config.modalId);
|
||||||
|
} else {
|
||||||
|
this.text(config.label(this.$t), () => {
|
||||||
|
this.$root.$emit('bv::show::modal', config.modalId);
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
debounceCheckUserAchievements: debounce(function debounceCheck () {
|
||||||
|
this.checkUserAchievements();
|
||||||
|
}, 700),
|
||||||
checkUserAchievements () {
|
checkUserAchievements () {
|
||||||
if (this.user.needsCron) return;
|
if (this.user.needsCron) return;
|
||||||
|
|
||||||
@@ -317,8 +380,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.user.stats.hp <= 0) {
|
if (this.user.stats.hp <= 0) {
|
||||||
this.playSound('Death');
|
this.showNotificationWithModal('DEATH');
|
||||||
this.$root.$emit('bv::show::modal', 'death');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.questCompleted) {
|
if (this.questCompleted) {
|
||||||
@@ -465,35 +527,20 @@ export default {
|
|||||||
this.$root.$emit('bv::show::modal', 'won-challenge');
|
this.$root.$emit('bv::show::modal', 'won-challenge');
|
||||||
break;
|
break;
|
||||||
case 'STREAK_ACHIEVEMENT':
|
case 'STREAK_ACHIEVEMENT':
|
||||||
this.streak(this.user.achievements.streak);
|
this.streak(this.user.achievements.streak, () => {
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
if (!this.user.preferences.suppressModals.streak) {
|
if (!this.user.preferences.suppressModals.streak) {
|
||||||
this.$root.$emit('bv::show::modal', 'streak');
|
this.$root.$emit('bv::show::modal', 'streak');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
this.playSound('Achievement_Unlocked');
|
||||||
break;
|
break;
|
||||||
case 'ULTIMATE_GEAR_ACHIEVEMENT':
|
case 'ULTIMATE_GEAR_ACHIEVEMENT':
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
this.$root.$emit('bv::show::modal', 'ultimate-gear');
|
|
||||||
break;
|
|
||||||
case 'REBIRTH_ACHIEVEMENT':
|
case 'REBIRTH_ACHIEVEMENT':
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
this.$root.$emit('bv::show::modal', 'rebirth');
|
|
||||||
break;
|
|
||||||
case 'GUILD_JOINED_ACHIEVEMENT':
|
case 'GUILD_JOINED_ACHIEVEMENT':
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
this.$root.$emit('bv::show::modal', 'joined-guild');
|
|
||||||
break;
|
|
||||||
case 'CHALLENGE_JOINED_ACHIEVEMENT':
|
case 'CHALLENGE_JOINED_ACHIEVEMENT':
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
this.$root.$emit('bv::show::modal', 'joined-challenge');
|
|
||||||
break;
|
|
||||||
case 'INVITED_FRIEND_ACHIEVEMENT':
|
case 'INVITED_FRIEND_ACHIEVEMENT':
|
||||||
this.playSound('Achievement_Unlocked');
|
|
||||||
this.$root.$emit('bv::show::modal', 'invited-friend');
|
|
||||||
break;
|
|
||||||
case 'NEW_CONTRIBUTOR_LEVEL':
|
case 'NEW_CONTRIBUTOR_LEVEL':
|
||||||
this.playSound('Achievement_Unlocked');
|
this.showNotificationWithModal(notification.type);
|
||||||
this.$root.$emit('bv::show::modal', 'contributor');
|
|
||||||
break;
|
break;
|
||||||
case 'CRON':
|
case 'CRON':
|
||||||
if (notification.data) {
|
if (notification.data) {
|
||||||
@@ -566,7 +613,7 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.checkUserAchievements();
|
this.debounceCheckUserAchievements();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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')
|
||||||
@@ -151,6 +151,14 @@ export default {
|
|||||||
this.$store.dispatch('snackbars:remove', this.notification);
|
this.$store.dispatch('snackbars:remove', this.notification);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
handleOnClick () {
|
||||||
|
if (typeof this.notification.onClick === 'function') {
|
||||||
|
this.notification.onClick();
|
||||||
|
}
|
||||||
|
this.show = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
message () {
|
message () {
|
||||||
if (this.notification.flavorMessage) {
|
if (this.notification.flavorMessage) {
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ export default {
|
|||||||
itemName,
|
itemName,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
streak (val) {
|
streak (val, onClick) {
|
||||||
this.notify(`${val}`, 'streak');
|
this.notify(`${val}`, 'streak', null, null, onClick, typeof onClick === 'undefined');
|
||||||
},
|
},
|
||||||
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,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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!",
|
||||||
|
|||||||
Reference in New Issue
Block a user