Commit 7edc1bc3 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement awarding emoji from emoji dropdown.

parent 575544f6
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* global Flash */ /* global Flash */
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import issueNotesEventHub from './notes/event_hub';
const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd'; const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd';
const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'; const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd';
...@@ -234,12 +235,23 @@ class AwardsHandler { ...@@ -234,12 +235,23 @@ class AwardsHandler {
} }
addAward(votesBlock, awardUrl, emoji, checkMutuality, callback) { addAward(votesBlock, awardUrl, emoji, checkMutuality, callback) {
if (this.isInIssuePage()) {
const id = votesBlock[0].id.replace('note_', '');
$('.emoji-menu').removeClass('is-visible');
$('.js-add-award.is-active').removeClass('is-active');
return issueNotesEventHub.$emit('toggleAward', { awardName: emoji, noteId: id });
}
const normalizedEmoji = this.emoji.normalizeEmojiName(emoji); const normalizedEmoji = this.emoji.normalizeEmojiName(emoji);
const $emojiButton = this.findEmojiIcon(votesBlock, normalizedEmoji).parent(); const $emojiButton = this.findEmojiIcon(votesBlock, normalizedEmoji).parent();
this.postEmoji($emojiButton, awardUrl, normalizedEmoji, () => { this.postEmoji($emojiButton, awardUrl, normalizedEmoji, () => {
this.addAwardToEmojiBar(votesBlock, normalizedEmoji, checkMutuality); this.addAwardToEmojiBar(votesBlock, normalizedEmoji, checkMutuality);
return typeof callback === 'function' ? callback() : undefined; return typeof callback === 'function' ? callback() : undefined;
}); });
$('.emoji-menu').removeClass('is-visible'); $('.emoji-menu').removeClass('is-visible');
$('.js-add-award.is-active').removeClass('is-active'); $('.js-add-award.is-active').removeClass('is-active');
} }
...@@ -267,7 +279,18 @@ class AwardsHandler { ...@@ -267,7 +279,18 @@ class AwardsHandler {
} }
} }
isInIssuePage() {
const page = gl.utils.getPagePath(1);
const action = gl.utils.getPagePath(2);
return page === 'issues' && action === 'show';
}
getVotesBlock() { getVotesBlock() {
if (this.isInIssuePage()) {
return $('.js-add-award.is-active').closest('.note.timeline-entry');
}
const currentBlock = $('.js-awards-block.current'); const currentBlock = $('.js-awards-block.current');
let resultantVotesBlock = currentBlock; let resultantVotesBlock = currentBlock;
if (currentBlock.length === 0) { if (currentBlock.length === 0) {
......
...@@ -73,6 +73,9 @@ export default { ...@@ -73,6 +73,9 @@ export default {
return orderedAwards; return orderedAwards;
}, },
isAuthoredByMe() {
return this.noteAuthorId === window.gon.current_user_id;
},
}, },
methods: { methods: {
getAwardHTML(name) { getAwardHTML(name) {
...@@ -178,10 +181,11 @@ export default { ...@@ -178,10 +181,11 @@ export default {
v-if="canAward" v-if="canAward"
class="award-menu-holder"> class="award-menu-holder">
<button <button
:class="{ 'js-user-authored': isAuthoredByMe }"
class="award-control btn has-tooltip js-add-award"
title="Add reaction"
aria-label="Add reaction" aria-label="Add reaction"
class="award-control btn has-tooltip"
data-placement="bottom" data-placement="bottom"
title="Add reaction"
type="button"> type="button">
<span <span
v-html="emojiSmiling" v-html="emojiSmiling"
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import storeOptions from '../stores/issue_notes_store'; import storeOptions from '../stores/issue_notes_store';
import eventHub from '../event_hub';
import IssueNote from './issue_note.vue'; import IssueNote from './issue_note.vue';
import IssueDiscussion from './issue_discussion.vue'; import IssueDiscussion from './issue_discussion.vue';
import IssueSystemNote from './issue_system_note.vue'; import IssueSystemNote from './issue_system_note.vue';
...@@ -29,6 +30,7 @@ export default { ...@@ -29,6 +30,7 @@ export default {
computed: { computed: {
...Vuex.mapGetters([ ...Vuex.mapGetters([
'notes', 'notes',
'notesById',
]), ]),
}, },
methods: { methods: {
...@@ -87,6 +89,13 @@ export default { ...@@ -87,6 +89,13 @@ export default {
new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line
}); });
}, 6000); }, 6000);
eventHub.$on('toggleAward', (data) => {
const { awardName, noteId } = data;
const endpoint = this.notesById[noteId].toggle_award_path;
this.$store.dispatch('toggleAward', { endpoint, awardName, noteId });
});
}, },
}; };
</script> </script>
......
import Vue from 'vue';
export default new Vue();
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