mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe
synced 2025-04-30 19:19:29 +08:00
supercedes #135 adapted from https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1431 Co-authored-by: Tusooa Zhu <tusooa@kazv.moe> Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: https://akkoma.dev/AkkomaGang/pleroma-fe/pulls/140
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
import ConfirmModal from '../confirm_modal/confirm_modal.vue'
|
|
import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate'
|
|
export default {
|
|
props: ['relationship', 'user', 'labelFollowing', 'buttonClass'],
|
|
components: {
|
|
ConfirmModal
|
|
},
|
|
data () {
|
|
return {
|
|
inProgress: false,
|
|
showingConfirmUnfollow: false
|
|
}
|
|
},
|
|
computed: {
|
|
shouldConfirmUnfollow () {
|
|
return this.$store.getters.mergedConfig.modalOnUnfollow
|
|
},
|
|
isPressed () {
|
|
return this.inProgress || this.relationship.following
|
|
},
|
|
title () {
|
|
if (this.inProgress || this.relationship.following) {
|
|
return this.$t('user_card.follow_unfollow')
|
|
} else if (this.relationship.requested) {
|
|
return this.$t('user_card.follow_cancel')
|
|
} else {
|
|
return this.$t('user_card.follow')
|
|
}
|
|
},
|
|
label () {
|
|
if (this.inProgress) {
|
|
return this.$t('user_card.follow_progress')
|
|
} else if (this.relationship.following) {
|
|
return this.labelFollowing || this.$t('user_card.following')
|
|
} else if (this.relationship.requested) {
|
|
return this.$t('user_card.follow_sent')
|
|
} else {
|
|
return this.$t('user_card.follow')
|
|
}
|
|
},
|
|
disabled () {
|
|
return this.inProgress || this.user.deactivated
|
|
}
|
|
},
|
|
methods: {
|
|
showConfirmUnfollow () {
|
|
this.showingConfirmUnfollow = true
|
|
},
|
|
hideConfirmUnfollow () {
|
|
this.showingConfirmUnfollow = false
|
|
},
|
|
onClick () {
|
|
this.relationship.following || this.relationship.requested ? this.unfollow() : this.follow()
|
|
},
|
|
follow () {
|
|
this.inProgress = true
|
|
requestFollow(this.relationship.id, this.$store).then(() => {
|
|
this.inProgress = false
|
|
})
|
|
},
|
|
unfollow () {
|
|
if (this.shouldConfirmUnfollow) {
|
|
this.showConfirmUnfollow()
|
|
} else {
|
|
this.doUnfollow()
|
|
}
|
|
},
|
|
doUnfollow () {
|
|
const store = this.$store
|
|
this.inProgress = true
|
|
requestUnfollow(this.relationship.id, store).then(() => {
|
|
this.inProgress = false
|
|
store.commit('removeStatus', { timeline: 'friends', userId: this.relationship.id })
|
|
})
|
|
|
|
this.hideConfirmUnfollow()
|
|
}
|
|
}
|
|
}
|