From 9869b6b38943cad9064d0c0906414686908ad733 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Sat, 8 Jul 2017 01:26:52 +0300 Subject: [PATCH] IssueNotesRefactor: Implement emoji actions from emoji list. --- .../notes/components/issue_note.vue | 2 +- .../notes/components/issue_note_actions.vue | 1 - .../components/issue_note_awards_list.vue | 29 ++++++++++++++- .../notes/components/issue_note_body.vue | 4 ++- .../notes/components/issue_note_header.vue | 2 +- .../notes/components/issue_notes.vue | 5 ++- .../notes/services/issue_notes_service.js | 3 ++ .../notes/stores/issue_notes_store.js | 35 +++++++++++++++++++ 8 files changed, 73 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/notes/components/issue_note.vue b/app/assets/javascripts/notes/components/issue_note.vue index 0c6d17e2302..1dd4786d605 100644 --- a/app/assets/javascripts/notes/components/issue_note.vue +++ b/app/assets/javascripts/notes/components/issue_note.vue @@ -82,7 +82,7 @@ export default { this.$store.dispatch('updateNote', data) .then(() => { this.isEditing = false; - $(this.$refs['noteBody'].$el).renderGFM(); + $(this.$refs.noteBody.$el).renderGFM(); }) .catch(() => { new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line diff --git a/app/assets/javascripts/notes/components/issue_note_actions.vue b/app/assets/javascripts/notes/components/issue_note_actions.vue index 60e0d10f8e7..88f0fdb9a25 100644 --- a/app/assets/javascripts/notes/components/issue_note_actions.vue +++ b/app/assets/javascripts/notes/components/issue_note_actions.vue @@ -1,5 +1,4 @@ @@ -138,9 +164,10 @@ export default {
diff --git a/app/assets/javascripts/notes/components/issue_note_header.vue b/app/assets/javascripts/notes/components/issue_note_header.vue index 879b7c0716b..cf2826e7b2e 100644 --- a/app/assets/javascripts/notes/components/issue_note_header.vue +++ b/app/assets/javascripts/notes/components/issue_note_header.vue @@ -41,7 +41,7 @@ export default { data() { return { isExpanded: true, - } + }; }, computed: { toggleChevronClass() { diff --git a/app/assets/javascripts/notes/components/issue_notes.vue b/app/assets/javascripts/notes/components/issue_notes.vue index d7ca0e3f688..4aa8bd1d1d8 100644 --- a/app/assets/javascripts/notes/components/issue_notes.vue +++ b/app/assets/javascripts/notes/components/issue_notes.vue @@ -3,7 +3,6 @@ import Vue from 'vue'; import Vuex from 'vuex'; -import { mapGetters } from 'vuex'; import storeOptions from '../stores/issue_notes_store'; import IssueNote from './issue_note.vue'; import IssueDiscussion from './issue_discussion.vue'; @@ -28,9 +27,9 @@ export default { IssueCommentForm, }, computed: { - ...mapGetters([ + ...Vuex.mapGetters([ 'notes', - ]) + ]), }, methods: { component(note) { diff --git a/app/assets/javascripts/notes/services/issue_notes_service.js b/app/assets/javascripts/notes/services/issue_notes_service.js index 0a9df556292..c80e23f02cb 100644 --- a/app/assets/javascripts/notes/services/issue_notes_service.js +++ b/app/assets/javascripts/notes/services/issue_notes_service.js @@ -28,4 +28,7 @@ export default { return Vue.http.get(endpoint, options); }, + toggleAward(endpoint, data) { + return Vue.http.post(endpoint, data, { emulateJSON: true }); + }, }; diff --git a/app/assets/javascripts/notes/stores/issue_notes_store.js b/app/assets/javascripts/notes/stores/issue_notes_store.js index 6f3dd24cad3..6a11c65fedc 100644 --- a/app/assets/javascripts/notes/stores/issue_notes_store.js +++ b/app/assets/javascripts/notes/stores/issue_notes_store.js @@ -84,6 +84,29 @@ const mutations = { storeState.notes.push(noteData); }, + toggleAward(storeState, data) { + const { awardName, note, action } = data; + const { id, name, username } = window.gl.currentUserData; + + if (action === 'add') { + note.award_emoji.push({ + name: awardName, + user: { id, name, username }, + }); + } else if (action === 'remove') { + let index = -1; + + note.award_emoji.forEach((a, i) => { + if (a.name === awardName && a.user.id === id) { + index = i; + } + }); + + if (index > -1) { + note.award_emoji.splice(index, 1); + } + } + }, }; const actions = { @@ -124,6 +147,7 @@ const actions = { }, createNewNote(context, data) { const { endpoint, noteData } = data; + return service .createNewNote(endpoint, noteData) .then(res => res.json()) @@ -164,6 +188,17 @@ const actions = { return res; }); }, + toggleAward(context, data) { + const { endpoint, awardName, action, noteId } = data; + const note = context.getters.notesById[noteId]; + + return service + .toggleAward(endpoint, { name: awardName }) + .then(res => res.json()) + .then(() => { + context.commit('toggleAward', { awardName, note, action }); + }); + }, }; export default {