aboutsummaryrefslogtreecommitdiff
path: root/src/components/follow_card/follow_card.js
blob: dc4a0d411ba8b261514e29e06cb70b91e3958742 (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
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
import RemoteFollow from '../remote_follow/remote_follow.vue'
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'

const FollowCard = {
  props: [
    'user',
    'noFollowsYou'
  ],
  data () {
    return {
      inProgress: false,
      requestSent: false
    }
  },
  components: {
    BasicUserCard,
    RemoteFollow
  },
  computed: {
    isMe () {
      return this.$store.state.users.currentUser.id === this.user.id
    },
    loggedIn () {
      return this.$store.state.users.currentUser
    }
  },
  methods: {
    followUser () {
      this.inProgress = true
      requestFollow(this.user, this.$store).then(({ sent }) => {
        this.inProgress = false
        this.requestSent = sent
      })
    },
    unfollowUser () {
      this.inProgress = true
      requestUnfollow(this.user, this.$store).then(() => {
        this.inProgress = false
      })
    }
  }
}

export default FollowCard