Commit cefc0af1 authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Fix emoji 100 bug: Creating strucutre to a forEach and then using...

[ci skip] Fix emoji 100 bug: Creating strucutre to a forEach and then using Object.keys was causing a type inconsistency
parent b8957b0d
...@@ -77,9 +77,7 @@ ...@@ -77,9 +77,7 @@
<div class="note-actions"> <div class="note-actions">
<span <span
v-if="accessLevel" v-if="accessLevel"
class="note-role"> class="note-role">{{accessLevel}}</span>
{{accessLevel}}
</span>
<a <a
v-tooltip v-tooltip
v-if="canAddAwardEmoji" v-if="canAddAwardEmoji"
......
...@@ -51,32 +51,22 @@ ...@@ -51,32 +51,22 @@
// } // }
// We need to do this otherwise we will render the same emoji over and over again. // We need to do this otherwise we will render the same emoji over and over again.
groupedAwards() { groupedAwards() {
const awards = {}; const awards = this.awards.reduce((acc, award) => {
const orderedAwards = {}; Object.assign(acc, {[award.name]: [award]});
return acc;
this.awards.forEach((award) => { }, {});
awards[award.name] = awards[award.name] || [];
awards[award.name].push(award);
});
const orderedAwards = {};
// Always show thumbsup and thumbsdown first // Always show thumbsup and thumbsdown first
const { thumbsup, thumbsdown } = awards; if (awards.thumbsup) {
if (thumbsup) {
orderedAwards.thumbsup = thumbsup; orderedAwards.thumbsup = thumbsup;
delete awards.thumbsup; delete awards.thumbsup;
} }
if (thumbsdown) { if (awards.thumbsdown) {
orderedAwards.thumbsdown = thumbsdown; orderedAwards.thumbsdown = thumbsdown;
delete awards.thumbsdown; delete awards.thumbsdown;
} }
return Object.assign({}, orderedAwards, awards);
// Because for-in forbidden
const keys = Object.keys(awards);
keys.forEach((key) => {
orderedAwards[key] = awards[key];
});
return orderedAwards;
}, },
isAuthoredByMe() { isAuthoredByMe() {
return this.noteAuthorId === window.gon.current_user_id; return this.noteAuthorId === window.gon.current_user_id;
...@@ -152,7 +142,8 @@ ...@@ -152,7 +142,8 @@
const data = { const data = {
endpoint: this.toggleAwardPath, endpoint: this.toggleAwardPath,
noteId: this.noteId, 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) this.toggleAward(data)
......
...@@ -101,7 +101,7 @@ export default { ...@@ -101,7 +101,7 @@ export default {
[types.TOGGLE_AWARD](state, data) { [types.TOGGLE_AWARD](state, data) {
const { awardName, note } = data; const { awardName, note } = data;
const { id, name, username } = window.gl.currentUserData; const { id, name, username } = state.userData;
let index = -1; let index = -1;
note.award_emoji.forEach((a, i) => { note.award_emoji.forEach((a, i) => {
...@@ -110,7 +110,7 @@ export default { ...@@ -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); note.award_emoji.splice(index, 1);
} else { } else {
note.award_emoji.push({ note.award_emoji.push({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment