summaryrefslogtreecommitdiffstats
path: root/web_src/js/components/ActivityHeatmap.vue
blob: 1970cb609a25397cb017cc24acfa82611c5ab26e (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
<template>
  <div class="heatmap-container">
    <div v-show="isLoading">
      <slot name="loading"/>
    </div>
    <div v-if="!isLoading" class="total-contributions">
      {{ values.length }} contributions in the last 12 months
    </div>
    <calendar-heatmap
      v-show="!isLoading"
      :locale="locale"
      :no-data-text="locale.no_contributions"
      :tooltip-unit="locale.contributions"
      :end-date="endDate"
      :values="values"
      :range-color="colorRange"
    />
  </div>
</template>
<script>
import {CalendarHeatmap} from 'vue-calendar-heatmap';
const {AppSubUrl, heatmapUser} = window.config;

export default {
  name: 'ActivityHeatmap',
  components: {CalendarHeatmap},
  data: () => ({
    isLoading: true,
    colorRange: [
      'var(--color-secondary-alpha-70)',
      'var(--color-primary-light-4)',
      'var(--color-primary-light-2)',
      'var(--color-primary)',
      'var(--color-primary-dark-2)',
      'var(--color-primary-dark-4)',
    ],
    endDate: new Date(),
    values: [],
    locale: {
      contributions: 'contributions',
      no_contributions: 'No contributions',
    },
  }),
  async mounted() {
    const res = await fetch(`${AppSubUrl}/api/v1/users/${heatmapUser}/heatmap`);
    const data = await res.json();
    this.values = data.map(({contributions, timestamp}) => {
      return {date: new Date(timestamp * 1000), count: contributions};
    });
    this.isLoading = false;
  },
};
</script>
<style scoped/>