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

star.js « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3deb629d5f2d008557207b172e431228c0c02a92 (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
import Flash from './flash';
import { __, s__ } from './locale';
import { spriteIcon } from './lib/utils/common_utils';
import axios from './lib/utils/axios_utils';

export default class Star {
  constructor() {
    $('.project-home-panel .toggle-star').on('click', function toggleStarClickCallback() {
      const $this = $(this);
      const $starSpan = $this.find('span');
      const $startIcon = $this.find('svg');

      axios.post($this.data('endpoint'))
        .then(({ data }) => {
          const isStarred = $starSpan.hasClass('starred');
          $this.parent().find('.star-count').text(data.star_count);

          if (isStarred) {
            $starSpan.removeClass('starred').text(s__('StarProject|Star'));
            $startIcon.remove();
            $this.prepend(spriteIcon('star-o'));
          } else {
            $starSpan.addClass('starred').text(__('Unstar'));
            $startIcon.remove();
            $this.prepend(spriteIcon('star'));
          }
        })
        .catch(() => Flash('Star toggle failed. Try again later.'));
    });
  }
}