yandere_fe/src/components/follow_button/follow_button.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

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
2020-04-22 05:06:10 -07:00
requestFollow(this.relationship.id, this.$store).then(() => {
2019-10-08 00:21:48 -07:00
this.inProgress = false
})
},
unfollow () {
const store = this.$store
this.inProgress = true
2020-04-22 05:06:10 -07:00
requestUnfollow(this.relationship.id, store).then(() => {
2019-10-08 00:21:48 -07:00
this.inProgress = false
2020-04-22 05:06:10 -07:00
store.commit('removeStatus', { timeline: 'friends', userId: this.relationship.id })
2019-10-08 00:21:48 -07:00
})
}
}
}