2019-10-08 00:21:48 -07:00
|
|
|
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
|
|
|
|
export default {
|
2020-04-21 13:27:51 -07:00
|
|
|
props: ['relationship', 'labelFollowing', 'buttonClass'],
|
2019-10-08 00:21:48 -07:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
inProgress: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isPressed () {
|
2020-04-21 13:27:51 -07:00
|
|
|
return this.inProgress || this.relationship.following
|
2019-10-08 00:21:48 -07:00
|
|
|
},
|
|
|
|
title () {
|
2020-04-21 13:27:51 -07:00
|
|
|
if (this.inProgress || this.relationship.following) {
|
2019-10-08 00:21:48 -07:00
|
|
|
return this.$t('user_card.follow_unfollow')
|
2020-04-21 13:27:51 -07:00
|
|
|
} else if (this.relationship.requested) {
|
2019-10-08 00:21:48 -07:00
|
|
|
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')
|
2020-04-21 13:27:51 -07:00
|
|
|
} else if (this.relationship.following) {
|
2019-10-17 06:19:52 -07:00
|
|
|
return this.labelFollowing || this.$t('user_card.following')
|
2020-04-21 13:27:51 -07:00
|
|
|
} else if (this.relationship.requested) {
|
2019-10-08 00:21:48 -07:00
|
|
|
return this.$t('user_card.follow_sent')
|
|
|
|
} else {
|
|
|
|
return this.$t('user_card.follow')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick () {
|
2020-04-21 13:27:51 -07:00
|
|
|
this.relationship.following ? this.unfollow() : this.follow()
|
2019-10-08 00:21:48 -07:00
|
|
|
},
|
|
|
|
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 })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|