[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:
parent
b8957b0d8a
commit
cefc0af14a
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue