summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/subscriptions/subscriptions.vue
blob: d69d100a26c104e12300431f0c20563f788dde85 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<script>
  import { __ } from '~/locale';
  import icon from '~/vue_shared/components/icon.vue';
  import toggleButton from '~/vue_shared/components/toggle_button.vue';
  import tooltip from '~/vue_shared/directives/tooltip';
  import eventHub from '../../event_hub';

  const ICON_ON = 'notifications';
  const ICON_OFF = 'notifications-off';
  const LABEL_ON = __('Notifications on');
  const LABEL_OFF = __('Notifications off');

  export default {
    directives: {
      tooltip,
    },
    components: {
      icon,
      toggleButton,
    },
    props: {
      loading: {
        type: Boolean,
        required: false,
        default: false,
      },
      subscribed: {
        type: Boolean,
        required: false,
        default: null,
      },
      id: {
        type: Number,
        required: false,
        default: null,
      },
    },
    computed: {
      showLoadingState() {
        return this.subscribed === null;
      },
      notificationIcon() {
        return this.subscribed ? ICON_ON : ICON_OFF;
      },
      notificationTooltip() {
        return this.subscribed ? LABEL_ON : LABEL_OFF;
      },
    },
    methods: {
      toggleSubscription() {
        eventHub.$emit('toggleSubscription', this.id);
      },
    },
  };
</script>

<template>
  <div>
    <div class="sidebar-collapsed-icon">
      <span
        v-tooltip
        :title="notificationTooltip"
        data-container="body"
        data-placement="left"
      >
        <icon
          :name="notificationIcon"
          :size="16"
          aria-hidden="true"
          class="sidebar-item-icon is-active"
        />
      </span>
    </div>
    <span class="issuable-header-text hide-collapsed pull-left">
      {{ __('Notifications') }}
    </span>
    <toggle-button
      ref="toggleButton"
      class="pull-right hide-collapsed js-issuable-subscribe-button"
      :is-loading="showLoadingState"
      :value="subscribed"
      @change="toggleSubscription"
    />
  </div>
</template>