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

issue_title.js « issue_show « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1184c8956dc0ae8c6aa344a86dccf682418af014 (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
import Visibility from 'visibilityjs';
import Poll from './../lib/utils/poll';
import Service from './services/index';

export default {
  props: {
    initialTitle: { required: true, type: String },
    endpoint: { required: true, type: String },
  },
  data() {
    const resource = new Service(this.$http, this.endpoint);

    const poll = new Poll({
      resource,
      method: 'getTitle',
      successCallback: (res) => {
        this.renderResponse(res);
      },
      errorCallback: (err) => {
        if (process.env.NODE_ENV !== 'production') {
          // eslint-disable-next-line no-console
          console.error('ISSUE SHOW TITLE REALTIME ERROR', err);
        } else {
          throw new Error(err);
        }
      },
    });

    return {
      poll,
      timeoutId: null,
      title: this.initialTitle,
    };
  },
  methods: {
    fetch() {
      this.poll.makeRequest();

      Visibility.change(() => {
        if (!Visibility.hidden()) {
          this.poll.restart();
        } else {
          this.poll.stop();
        }
      });
    },
    renderResponse(res) {
      const body = JSON.parse(res.body);
      this.triggerAnimation(body);
    },
    triggerAnimation(body) {
      const { title } = body;

      /**
      * since opacity is changed, even if there is no diff for Vue to update
      * we must check the title even on a 304 to ensure no visual change
      */
      if (this.title === title) return;

      this.$el.style.opacity = 0;

      this.timeoutId = setTimeout(() => {
        this.title = title;

        this.$el.style.transition = 'opacity 0.2s ease';
        this.$el.style.opacity = 1;

        clearTimeout(this.timeoutId);
      }, 100);
    },
  },
  created() {
    this.fetch();
  },
  template: `
    <h2 class='title' v-html='title'></h2>
  `,
};