aboutsummaryrefslogtreecommitdiff
path: root/src/components/user_card/user_card.js
blob: a4c84716d0c398b9287597f82a2dbe824145507f (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
55
56
57
58
59
60
61
62
63
64
65
import UserCardContent from '../user_card_content/user_card_content.vue'
import UserAvatar from '../user_avatar/user_avatar.vue'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'

const UserCard = {
  props: [
    'user',
    'showFollows',
    'showApproval',
    'showActions'
  ],
  data () {
    return {
      userExpanded: false,
      followRequestInProgress: false,
      followRequestSent: false,
      updated: false
    }
  },
  components: {
    UserCardContent,
    UserAvatar
  },
  computed: {
    currentUser () { return this.$store.state.users.currentUser },
    following () { return this.updated ? this.updated.following : this.user.following },
    showFollow () {
      return this.showActions && (!this.showFollows && !this.following || this.updated && !this.updated.following)
    }
  },
  methods: {
    toggleUserExpanded () {
      this.userExpanded = !this.userExpanded
    },
    approveUser () {
      this.$store.state.api.backendInteractor.approveUser(this.user.id)
      this.$store.dispatch('removeFollowRequest', this.user)
    },
    denyUser () {
      this.$store.state.api.backendInteractor.denyUser(this.user.id)
      this.$store.dispatch('removeFollowRequest', this.user)
    },
    userProfileLink (user) {
      return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames)
    },
    followUser () {
      this.followRequestInProgress = true
      requestFollow(this.user, this.$store).then(({ sent, updated }) => {
        this.followRequestInProgress = false
        this.followRequestSent = sent
        this.updated = updated
      })
    },
    unfollowUser () {
      this.followRequestInProgress = true
      requestUnfollow(this.user, this.$store).then(({ updated }) => {
        this.followRequestInProgress = false
        this.updated = updated
      })
    }
  }
}

export default UserCard