aboutsummaryrefslogtreecommitdiff
path: root/src/components/follow_card/follow_card.js
blob: 7a16f4554a0f1a235ca5141907150970ea925602 (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
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,
      updated: false
    }
  },
  components: {
    BasicUserCard,
    RemoteFollow
  },
  computed: {
    isMe () { return this.$store.state.users.currentUser.id === this.user.id },
    following () { return this.updated ? this.updated.following : this.user.following },
    showFollow () {
      return !this.following || (this.updated && !this.updated.following)
    },
    loggedIn () {
      return this.$store.state.users.currentUser
    }
  },
  methods: {
    followUser () {
      this.inProgress = true
      requestFollow(this.user, this.$store).then(({ sent, updated }) => {
        this.inProgress = false
        this.requestSent = sent
        this.updated = updated
      })
    },
    unfollowUser () {
      this.inProgress = true
      requestUnfollow(this.user, this.$store).then(({ updated }) => {
        this.inProgress = false
        this.updated = updated
      })
    }
  }
}

export default FollowCard