summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/emoji/awards_app/index.js
blob: 931407f4cf7ede558573000650ab949d52af1194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Vue from 'vue';
import { mapActions, mapState } from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils';
import AwardsList from '~/vue_shared/components/awards_list.vue';
import createstore from './store';

export default (el) => {
  if (!el) return null;

  const {
    dataset: { path },
  } = el;
  const canAwardEmoji = parseBoolean(el.dataset.canAwardEmoji);

  return new Vue({
    el,
    name: 'AwardsListRoot',
    store: createstore(),
    computed: {
      ...mapState(['currentUserId', 'canAwardEmoji', 'awards']),
    },
    created() {
      this.setInitialData({ path, currentUserId: window.gon.current_user_id, canAwardEmoji });
    },
    mounted() {
      this.fetchAwards();
    },
    methods: {
      ...mapActions(['setInitialData', 'fetchAwards', 'toggleAward']),
    },
    render(createElement) {
      return createElement(AwardsList, {
        props: {
          awards: this.awards,
          canAwardEmoji: this.canAwardEmoji,
          currentUserId: this.currentUserId,
          defaultAwards: ['thumbsup', 'thumbsdown'],
          selectedClass: 'selected',
        },
        on: {
          award: this.toggleAward,
        },
      });
    },
  });
};