aboutsummaryrefslogtreecommitdiff
path: root/src/components/favorite_button/favorite_button.js
blob: a2b4cb656bf37d23657c434d36d9600f18399c7f (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
const FavoriteButton = {
  props: ['status', 'loggedIn'],
  data () {
    return {
      hidePostStatsLocal: typeof this.$store.state.config.hidePostStats === 'undefined'
        ? this.$store.state.instance.hidePostStats
        : this.$store.state.config.hidePostStats,
      animated: false
    }
  },
  methods: {
    favorite () {
      if (!this.status.favorited) {
        this.$store.dispatch('favorite', {id: this.status.id})
      } else {
        this.$store.dispatch('unfavorite', {id: this.status.id})
      }
      this.animated = true
      setTimeout(() => {
        this.animated = false
      }, 500)
    }
  },
  computed: {
    classes () {
      return {
        'icon-star-empty': !this.status.favorited,
        'icon-star': this.status.favorited,
        'animate-spin': this.animated
      }
    }
  }
}

export default FavoriteButton