diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-08-02 15:39:47 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-08-02 15:39:47 +0100 |
commit | 7b093581826612f3627ff75b74056b7294988453 (patch) | |
tree | 441fc56fea28d625636439336d08e335f03cb833 /app/assets/javascripts/notes/stores | |
parent | d8ebcb747acdc80a6f6cffe5b28c58044f40341e (diff) | |
download | gitlab-ce-7b093581826612f3627ff75b74056b7294988453.tar.gz |
[ci skip] Fix emoji being posted twice originating an error
Diffstat (limited to 'app/assets/javascripts/notes/stores')
-rw-r--r-- | app/assets/javascripts/notes/stores/actions.js | 35 | ||||
-rw-r--r-- | app/assets/javascripts/notes/stores/mutations.js | 13 |
2 files changed, 12 insertions, 36 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index 6d60c46d49b..0c9eb046298 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -174,7 +174,7 @@ export const poll = ({ commit, state, getters }) => { if (!Visibility.hidden()) { eTagPoll.makeRequest(); } else { - this.service.poll(requestData); + service.poll(requestData); } Visibility.change(() => { @@ -186,38 +186,17 @@ export const poll = ({ commit, state, getters }) => { }); }; -export const toggleAward = ({ commit, getters, dispatch }, data) => { - const { endpoint, awardName, noteId, skipMutalityCheck } = data; - const note = getters.notesById[noteId]; +export const toggleAward = ({ commit, state, getters, dispatch }, { awardName, noteId }) => { + commit(types.TOGGLE_AWARD, { awardName, note: getters.notesById[noteId] }); +}; +export const toggleAwardRequest = ({ commit, getters, dispatch }, data) => { + const { endpoint, awardName } = data; return service .toggleAward(endpoint, { name: awardName }) .then(res => res.json()) .then(() => { - commit(types.TOGGLE_AWARD, { awardName, note }); - - if (!skipMutalityCheck && - (awardName === constants.EMOJI_THUMBSUP || awardName === constants.EMOJI_THUMBSDOWN)) { - const counterAward = awardName === constants.EMOJI_THUMBSUP ? - constants.EMOJI_THUMBSDOWN : - constants.EMOJI_THUMBSUP; - - const targetNote = getters.notesById[noteId]; - let noteHasAwardByCurrentUser = false; - - targetNote.award_emoji.forEach((a) => { - if (a.name === counterAward && a.user.id === window.gon.current_user_id) { - noteHasAwardByCurrentUser = true; - } - }); - - if (noteHasAwardByCurrentUser) { - Object.assign(data, { awardName: counterAward }); - Object.assign(data, { skipMutalityCheck: true }); - - dispatch(types.TOGGLE_AWARD, data); - } - } + dispatch('toggleAward', data); }); }; diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js index 15179a22b83..f77f19c9b3c 100644 --- a/app/assets/javascripts/notes/stores/mutations.js +++ b/app/assets/javascripts/notes/stores/mutations.js @@ -102,16 +102,13 @@ export default { [types.TOGGLE_AWARD](state, data) { const { awardName, note } = data; const { id, name, username } = state.userData; - let index = -1; - note.award_emoji.forEach((a, i) => { - if (a.name === awardName && a.user.id === id) { - index = i; - } - }); + const hasEmojiAwardedByCurrentUser = note.award_emoji + .filter(emoji => emoji.name === data.awardName && emoji.user.id === id); - if (index > -1) { // If current user has awarded this emoji, remove it. - note.award_emoji.splice(index, 1); + if (hasEmojiAwardedByCurrentUser.length) { + // If current user has awarded this emoji, remove it. + note.award_emoji.splice(note.award_emoji.indexOf(hasEmojiAwardedByCurrentUser[0]), 1); } else { note.award_emoji.push({ name: awardName, |