Client Fixes Oct 1 (#9126)

* fix exp notifications for armoire

* open the profile modal only if data is available
This commit is contained in:
Matteo Pagliazzi
2017-10-02 23:01:27 +02:00
committed by GitHub
parent 4e97355110
commit 47ebee9ae8
4 changed files with 38 additions and 17 deletions

View File

@@ -472,10 +472,15 @@ export default {
}); });
}, },
showMemberModal (memberId) { showMemberModal (memberId) {
// @TODO move to action or anyway move from here because it's super duplicate const profile = this.cachedProfileData[memberId];
this.$store.state.profileUser = this.cachedProfileData[memberId];
this.$store.state.profileOptions.startingPage = 'profile'; // Open the modal only if the data is available
this.$root.$emit('show::modal', 'profile'); if (profile && !profile.rejected) {
// @TODO move to action or anyway move from here because it's super duplicate
this.$store.state.profileUser = profile;
this.$store.state.profileOptions.startingPage = 'profile';
this.$root.$emit('show::modal', 'profile');
}
}, },
}, },
}; };

View File

@@ -31,3 +31,22 @@ export function getDropClass ({type, key}) {
return dropClass; return dropClass;
} }
export function getSign (number) {
let sign = '+';
if (number && number < 0) {
sign = '-';
}
return sign;
}
export function round (number, nDigits) {
return Math.abs(number.toFixed(nDigits || 1));
}
export function getXPMessage (val) {
if (val < -50) return; // don't show when they level up (resetting their exp)
return `${getSign(val)} ${round(val)}`;
}

View File

@@ -1,6 +1,6 @@
import habiticaMarkdown from 'habitica-markdown'; import habiticaMarkdown from 'habitica-markdown';
import { mapState } from 'client/libs/store'; import { mapState } from 'client/libs/store';
import { getDropClass } from 'client/libs/notifications'; import { getDropClass, getXPMessage, getSign, round } from 'client/libs/notifications';
export default { export default {
computed: { computed: {
@@ -22,8 +22,7 @@ export default {
this.notify(this.$t(type, { val }), 'success'); this.notify(this.$t(type, { val }), 'success');
}, },
exp (val) { exp (val) {
if (val < -50) return; // don't show when they level up (resetting their exp) let message = getXPMessage(val);
let message = `${this.sign(val)} ${this.round(val)}`;
this.notify(message, 'xp', 'glyphicon glyphicon-star', this.sign(val)); this.notify(message, 'xp', 'glyphicon glyphicon-star', this.sign(val));
}, },
error (error) { error (error) {
@@ -60,14 +59,10 @@ export default {
this.notify(val, 'info', null, null, onClick); this.notify(val, 'info', null, null, onClick);
}, },
sign (number) { sign (number) {
let sign = '+'; return getSign(number);
if (number && number < 0) {
sign = '-';
}
return sign;
}, },
round (number, nDigits) { round (number, nDigits) {
return Math.abs(number.toFixed(nDigits || 1)); return round(number, nDigits);
}, },
notify (html, type, icon, sign) { notify (html, type, icon, sign) {
this.notifications.push({ this.notifications.push({

View File

@@ -81,16 +81,18 @@ export async function genericPurchase (store, params) {
let result = await axios.post('/api/v3/user/buy-armoire'); let result = await axios.post('/api/v3/user/buy-armoire');
buyResult = result.data.data; buyResult = result.data.data;
// @TODO: We might need to abstract notifications to library rather than mixin
if (buyResult) { if (buyResult) {
const resData = buyResult; const resData = buyResult;
const item = resData.armoire; const item = resData.armoire;
const isExperience = item.type === 'experience';
// @TODO: We might need to abstract notifications to library rather than mixin
store.state.notificationStore.push({ store.state.notificationStore.push({
title: '', title: '',
text: item.dropText, text: isExperience ? item.value : item.dropText,
type: item.type === 'experience' ? 'xp' : 'drop', type: isExperience ? 'xp' : 'drop',
icon: item.type === 'experience' ? null : getDropClass({type: item.type, key: item.dropKey}), icon: isExperience ? null : getDropClass({type: item.type, key: item.dropKey}),
timeout: true, timeout: true,
}); });
} }