Commit 9869b6b3 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement emoji actions from emoji list.

parent deed4725
...@@ -82,7 +82,7 @@ export default { ...@@ -82,7 +82,7 @@ export default {
this.$store.dispatch('updateNote', data) this.$store.dispatch('updateNote', data)
.then(() => { .then(() => {
this.isEditing = false; this.isEditing = false;
$(this.$refs['noteBody'].$el).renderGFM(); $(this.$refs.noteBody.$el).renderGFM();
}) })
.catch(() => { .catch(() => {
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
......
<script> <script>
import Vue from 'vue';
import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg'; import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg';
import emojiSmile from 'icons/_emoji_smile.svg'; import emojiSmile from 'icons/_emoji_smile.svg';
import emojiSmiley from 'icons/_emoji_smiley.svg'; import emojiSmiley from 'icons/_emoji_smiley.svg';
......
<script> <script>
/* global Flash */
import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg'; import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg';
import emojiSmile from 'icons/_emoji_smile.svg'; import emojiSmile from 'icons/_emoji_smile.svg';
import emojiSmiley from 'icons/_emoji_smiley.svg'; import emojiSmiley from 'icons/_emoji_smiley.svg';
...@@ -10,10 +12,18 @@ export default { ...@@ -10,10 +12,18 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
toggleAwardPath: {
type: String,
required: true,
},
noteAuthorId: { noteAuthorId: {
type: Number, type: Number,
required: true, required: true,
}, },
noteId: {
type: Number,
required: true,
},
}, },
data() { data() {
const userId = window.gon.current_user_id; const userId = window.gon.current_user_id;
...@@ -129,6 +139,22 @@ export default { ...@@ -129,6 +139,22 @@ export default {
return title; return title;
}, },
handleAward(awardName, isAwarded) {
const data = {
endpoint: this.toggleAwardPath,
action: isAwarded ? 'remove' : 'add',
noteId: this.noteId,
awardName,
};
this.$store.dispatch('toggleAward', data)
.then(() => {
$(this.$el).find('.award-control').tooltip('fixTitle');
})
.catch(() => {
new Flash('Something went wrong on our end.'); // eslint-disable-line
});
},
}, },
}; };
</script> </script>
...@@ -138,9 +164,10 @@ export default { ...@@ -138,9 +164,10 @@ export default {
<div class="awards js-awards-block"> <div class="awards js-awards-block">
<button <button
v-for="(awardList, awardName) in groupedAwards" v-for="(awardList, awardName) in groupedAwards"
class="btn award-control has-tooltip"
:class="getAwardClassBindings(awardList, awardName)" :class="getAwardClassBindings(awardList, awardName)"
:title="awardTitle(awardList)" :title="awardTitle(awardList)"
@click="handleAward(awardName, amIAwarded(awardList))"
class="btn award-control has-tooltip"
data-placement="bottom" data-placement="bottom"
type="button"> type="button">
<span v-html="getAwardHTML(awardName)"></span> <span v-html="getAwardHTML(awardName)"></span>
......
...@@ -64,7 +64,9 @@ export default { ...@@ -64,7 +64,9 @@ export default {
actionText="Edited" /> actionText="Edited" />
<issue-note-awards-list <issue-note-awards-list
v-if="note.award_emoji.length" v-if="note.award_emoji.length"
:noteId="note.id"
:noteAuthorId="note.author.id"
:awards="note.award_emoji" :awards="note.award_emoji"
:noteAuthorId="note.author.id" /> :toggleAwardPath="note.toggle_award_path" />
</div> </div>
</template> </template>
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
data() { data() {
return { return {
isExpanded: true, isExpanded: true,
} };
}, },
computed: { computed: {
toggleChevronClass() { toggleChevronClass() {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { mapGetters } from 'vuex';
import storeOptions from '../stores/issue_notes_store'; import storeOptions from '../stores/issue_notes_store';
import IssueNote from './issue_note.vue'; import IssueNote from './issue_note.vue';
import IssueDiscussion from './issue_discussion.vue'; import IssueDiscussion from './issue_discussion.vue';
...@@ -28,9 +27,9 @@ export default { ...@@ -28,9 +27,9 @@ export default {
IssueCommentForm, IssueCommentForm,
}, },
computed: { computed: {
...mapGetters([ ...Vuex.mapGetters([
'notes', 'notes',
]) ]),
}, },
methods: { methods: {
component(note) { component(note) {
......
...@@ -28,4 +28,7 @@ export default { ...@@ -28,4 +28,7 @@ export default {
return Vue.http.get(endpoint, options); return Vue.http.get(endpoint, options);
}, },
toggleAward(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
}; };
...@@ -84,6 +84,29 @@ const mutations = { ...@@ -84,6 +84,29 @@ const mutations = {
storeState.notes.push(noteData); 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 = { const actions = {
...@@ -124,6 +147,7 @@ const actions = { ...@@ -124,6 +147,7 @@ const actions = {
}, },
createNewNote(context, data) { createNewNote(context, data) {
const { endpoint, noteData } = data; const { endpoint, noteData } = data;
return service return service
.createNewNote(endpoint, noteData) .createNewNote(endpoint, noteData)
.then(res => res.json()) .then(res => res.json())
...@@ -164,6 +188,17 @@ const actions = { ...@@ -164,6 +188,17 @@ const actions = {
return res; 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 { export default {
......
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