pleroma-fe/src/components/user_card/user_card.js

64 lines
2 KiB
JavaScript
Raw Normal View History

2017-08-21 20:25:01 +03:00
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'
2017-08-21 20:25:01 +03:00
const UserCard = {
props: [
'user',
2019-02-17 18:54:22 +02:00
'noFollowsYou',
'showApproval'
2017-08-21 20:25:01 +03:00
],
data () {
return {
userExpanded: false,
followRequestInProgress: false,
followRequestSent: false,
updated: false
2017-08-21 20:25:01 +03:00
}
},
components: {
UserCardContent,
UserAvatar
2017-08-21 20:25:01 +03:00
},
computed: {
currentUser () { return this.$store.state.users.currentUser },
following () { return this.updated ? this.updated.following : this.user.following },
showFollow () {
2019-02-17 18:54:22 +02:00
return !this.showApproval && (!this.following || this.updated && !this.updated.following)
}
},
2017-08-21 20:25:01 +03:00
methods: {
toggleUserExpanded () {
this.userExpanded = !this.userExpanded
2018-06-07 00:58:44 +00:00
},
approveUser () {
this.$store.state.api.backendInteractor.approveUser(this.user.id)
this.$store.dispatch('removeFollowRequest', this.user)
2018-06-07 00:58:44 +00:00
},
denyUser () {
this.$store.state.api.backendInteractor.denyUser(this.user.id)
this.$store.dispatch('removeFollowRequest', this.user)
2018-12-17 02:52:27 +03:00
},
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
})
2017-08-21 20:25:01 +03:00
}
}
}
export default UserCard