debian-mirror-gitlab/app/assets/javascripts/notes/components/note_awards_list.vue

72 lines
1.4 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-05-09 12:01:36 +05:30
import { mapActions, mapGetters } from 'vuex';
2021-09-30 23:02:18 +05:30
import createFlash from '~/flash';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2020-04-22 19:07:51 +05:30
import AwardsList from '~/vue_shared/components/awards_list.vue';
2018-05-09 12:01:36 +05:30
export default {
2018-12-13 13:39:08 +05:30
components: {
2020-04-22 19:07:51 +05:30
AwardsList,
2018-05-09 12:01:36 +05:30
},
props: {
awards: {
type: Array,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
toggleAwardPath: {
type: String,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
noteAuthorId: {
type: Number,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
noteId: {
2018-11-20 20:47:30 +05:30
type: String,
2018-05-09 12:01:36 +05:30
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
canAwardEmoji: {
type: Boolean,
required: true,
},
},
computed: {
...mapGetters(['getUserData']),
isAuthoredByMe() {
return this.noteAuthorId === this.getUserData.id;
},
2020-04-22 19:07:51 +05:30
addButtonClass() {
return this.isAuthoredByMe ? 'js-user-authored' : '';
},
2018-05-09 12:01:36 +05:30
},
methods: {
...mapActions(['toggleAwardRequest']),
handleAward(awardName) {
const data = {
endpoint: this.toggleAwardPath,
noteId: this.noteId,
2020-04-22 19:07:51 +05:30
awardName,
2018-05-09 12:01:36 +05:30
};
2021-09-30 23:02:18 +05:30
this.toggleAwardRequest(data).catch(() =>
createFlash({
message: __('Something went wrong on our end.'),
}),
);
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div class="note-awards">
2020-04-22 19:07:51 +05:30
<awards-list
:awards="awards"
:can-award-emoji="canAwardEmoji"
:current-user-id="getUserData.id"
:add-button-class="addButtonClass"
@award="handleAward($event)"
/>
2018-03-17 18:26:18 +05:30
</div>
</template>