aboutsummaryrefslogtreecommitdiff
path: root/src/components/follow_button/follow_button.js
blob: 12da264545fbcb8947a834adc9bcfae03e4b01d5 (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
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
export default {
  props: ['user', 'labelFollowing', 'buttonClass'],
  data () {
    return {
      inProgress: false
    }
  },
  computed: {
    isPressed () {
      return this.inProgress || this.user.following
    },
    title () {
      if (this.inProgress || this.user.following) {
        return this.$t('user_card.follow_unfollow')
      } else if (this.user.requested) {
        return this.$t('user_card.follow_again')
      } else {
        return this.$t('user_card.follow')
      }
    },
    label () {
      if (this.inProgress) {
        return this.$t('user_card.follow_progress')
      } else if (this.user.following) {
        return this.labelFollowing || this.$t('user_card.following')
      } else if (this.user.requested) {
        return this.$t('user_card.follow_sent')
      } else {
        return this.$t('user_card.follow')
      }
    }
  },
  methods: {
    onClick () {
      this.user.following ? this.unfollow() : this.follow()
    },
    follow () {
      this.inProgress = true
      requestFollow(this.user, this.$store).then(() => {
        this.inProgress = false
      })
    },
    unfollow () {
      const store = this.$store
      this.inProgress = true
      requestUnfollow(this.user, store).then(() => {
        this.inProgress = false
        store.commit('removeStatus', { timeline: 'friends', userId: this.user.id })
      })
    }
  }
}