[ci skip] Fix emoji 100 bug: Creating strucutre to a forEach and then using Object.keys was causing a type inconsistency

This commit is contained in:
Filipa Lacerda 2017-07-29 22:56:12 +01:00
parent b8957b0d8a
commit cefc0af14a
3 changed files with 13 additions and 24 deletions

View File

@ -77,9 +77,7 @@
<div class="note-actions">
<span
v-if="accessLevel"
class="note-role">
{{accessLevel}}
</span>
class="note-role">{{accessLevel}}</span>
<a
v-tooltip
v-if="canAddAwardEmoji"

View File

@ -51,32 +51,22 @@
// }
// We need to do this otherwise we will render the same emoji over and over again.
groupedAwards() {
const awards = {};
const awards = this.awards.reduce((acc, award) => {
Object.assign(acc, {[award.name]: [award]});
return acc;
}, {});
const orderedAwards = {};
this.awards.forEach((award) => {
awards[award.name] = awards[award.name] || [];
awards[award.name].push(award);
});
// Always show thumbsup and thumbsdown first
const { thumbsup, thumbsdown } = awards;
if (thumbsup) {
if (awards.thumbsup) {
orderedAwards.thumbsup = thumbsup;
delete awards.thumbsup;
}
if (thumbsdown) {
if (awards.thumbsdown) {
orderedAwards.thumbsdown = thumbsdown;
delete awards.thumbsdown;
}
// Because for-in forbidden
const keys = Object.keys(awards);
keys.forEach((key) => {
orderedAwards[key] = awards[key];
});
return orderedAwards;
return Object.assign({}, orderedAwards, awards);
},
isAuthoredByMe() {
return this.noteAuthorId === window.gon.current_user_id;
@ -152,7 +142,8 @@
const data = {
endpoint: this.toggleAwardPath,
noteId: this.noteId,
awardName,
// 100 emoji is a number. Callback for v-for click sends it as a string
awardName: awardName === "100" ? 100: awardName,
};
this.toggleAward(data)

View File

@ -101,7 +101,7 @@ export default {
[types.TOGGLE_AWARD](state, data) {
const { awardName, note } = data;
const { id, name, username } = window.gl.currentUserData;
const { id, name, username } = state.userData;
let index = -1;
note.award_emoji.forEach((a, i) => {
@ -110,7 +110,7 @@ export default {
}
});
if (index > -1) { // if I am awarded, remove my award
if (index > -1) { // If current user has awarded this emoji, remove it.
note.award_emoji.splice(index, 1);
} else {
note.award_emoji.push({