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

80 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-02-09 21:50:04 +01:00
import ConfirmModal from '../confirm_modal/confirm_modal.vue'
2019-10-08 09:21:48 +02:00
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
export default {
props: ['relationship', 'user', 'labelFollowing', 'buttonClass'],
2022-02-09 21:50:04 +01:00
components: {
ConfirmModal
},
2019-10-08 09:21:48 +02:00
data () {
return {
2022-02-09 21:50:04 +01:00
inProgress: false,
2022-02-09 23:03:17 +01:00
showingConfirmUnfollow: false
2019-10-08 09:21:48 +02:00
}
},
computed: {
2022-02-09 21:50:04 +01:00
shouldConfirmUnfollow () {
return this.$store.getters.mergedConfig.modalOnUnfollow
},
2019-10-08 09:21:48 +02:00
isPressed () {
2020-04-21 22:27:51 +02:00
return this.inProgress || this.relationship.following
2019-10-08 09:21:48 +02:00
},
title () {
2020-04-21 22:27:51 +02:00
if (this.inProgress || this.relationship.following) {
2019-10-08 09:21:48 +02:00
return this.$t('user_card.follow_unfollow')
2020-04-21 22:27:51 +02:00
} else if (this.relationship.requested) {
return this.$t('user_card.follow_cancel')
2019-10-08 09:21:48 +02:00
} else {
return this.$t('user_card.follow')
}
},
label () {
if (this.inProgress) {
return this.$t('user_card.follow_progress')
2020-04-21 22:27:51 +02:00
} else if (this.relationship.following) {
2019-10-17 15:19:52 +02:00
return this.labelFollowing || this.$t('user_card.following')
2020-04-21 22:27:51 +02:00
} else if (this.relationship.requested) {
2019-10-08 09:21:48 +02:00
return this.$t('user_card.follow_sent')
} else {
return this.$t('user_card.follow')
}
},
disabled () {
return this.inProgress || this.user.deactivated
2019-10-08 09:21:48 +02:00
}
},
methods: {
2022-02-09 21:50:04 +01:00
showConfirmUnfollow () {
this.showingConfirmUnfollow = true
},
hideConfirmUnfollow () {
this.showingConfirmUnfollow = false
},
2019-10-08 09:21:48 +02:00
onClick () {
this.relationship.following || this.relationship.requested ? this.unfollow() : this.follow()
2019-10-08 09:21:48 +02:00
},
follow () {
this.inProgress = true
2020-04-22 14:06:10 +02:00
requestFollow(this.relationship.id, this.$store).then(() => {
2019-10-08 09:21:48 +02:00
this.inProgress = false
})
},
unfollow () {
2022-02-09 21:50:04 +01:00
if (this.shouldConfirmUnfollow) {
this.showConfirmUnfollow()
} else {
this.doUnfollow()
}
},
doUnfollow () {
2019-10-08 09:21:48 +02:00
const store = this.$store
this.inProgress = true
2020-04-22 14:06:10 +02:00
requestUnfollow(this.relationship.id, store).then(() => {
2019-10-08 09:21:48 +02:00
this.inProgress = false
2020-04-22 14:06:10 +02:00
store.commit('removeStatus', { timeline: 'friends', userId: this.relationship.id })
2019-10-08 09:21:48 +02:00
})
2022-02-09 21:50:04 +01:00
this.hideConfirmUnfollow()
2019-10-08 09:21:48 +02:00
}
}
}