Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « awards_app « emoji « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 965cb4f421a8ba5816ee1a6e8d4e377e4e0e1e70 (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
47
48
49
50
51
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
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, newCustomEmojiPath },
  } = el;
  const canAwardEmoji = parseBoolean(el.dataset.canAwardEmoji);
  const showDefaultAwardEmojis = parseBoolean(el.dataset.showDefaultAwardEmojis);

  return new Vue({
    el,
    name: 'AwardsListRoot',
    store: createstore(),
    provide: {
      newCustomEmojiPath,
    },
    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: showDefaultAwardEmojis ? ['thumbsup', 'thumbsdown'] : [],
          selectedClass: 'selected',
        },
        on: {
          award: this.toggleAward,
        },
      });
    },
  });
};