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

89 lines
2.3 KiB
JavaScript
Raw Normal View History

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