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) {
const profile = this.cachedProfileData[memberId];
// Open the modal only if the data is available
if (profile && !profile.rejected) {
// @TODO move to action or anyway move from here because it's super duplicate
this.$store.state.profileUser = this.cachedProfileData[memberId];
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;
}
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 { mapState } from 'client/libs/store';
import { getDropClass } from 'client/libs/notifications';
import { getDropClass, getXPMessage, getSign, round } from 'client/libs/notifications';
export default {
computed: {
@@ -22,8 +22,7 @@ export default {
this.notify(this.$t(type, { val }), 'success');
},
exp (val) {
if (val < -50) return; // don't show when they level up (resetting their exp)
let message = `${this.sign(val)} ${this.round(val)}`;
let message = getXPMessage(val);
this.notify(message, 'xp', 'glyphicon glyphicon-star', this.sign(val));
},
error (error) {
@@ -60,14 +59,10 @@ export default {
this.notify(val, 'info', null, null, onClick);
},
sign (number) {
let sign = '+';
if (number && number < 0) {
sign = '-';
}
return sign;
return getSign(number);
},
round (number, nDigits) {
return Math.abs(number.toFixed(nDigits || 1));
return round(number, nDigits);
},
notify (html, type, icon, sign) {
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');
buyResult = result.data.data;
// @TODO: We might need to abstract notifications to library rather than mixin
if (buyResult) {
const resData = buyResult;
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({
title: '',
text: item.dropText,
type: item.type === 'experience' ? 'xp' : 'drop',
icon: item.type === 'experience' ? null : getDropClass({type: item.type, key: item.dropKey}),
text: isExperience ? item.value : item.dropText,
type: isExperience ? 'xp' : 'drop',
icon: isExperience ? null : getDropClass({type: item.type, key: item.dropKey}),
timeout: true,
});
}