pleroma-fe/src/components/status_action_buttons/action_button.js

151 lines
3.3 KiB
JavaScript
Raw Normal View History

2026-01-08 17:26:52 +02:00
import EmojiPicker from 'src/components/emoji_picker/emoji_picker.vue'
import Popover from 'src/components/popover/popover.vue'
import StatusBookmarkFolderMenu from 'src/components/status_bookmark_folder_menu/status_bookmark_folder_menu.vue'
import { useInstanceStore } from 'src/stores/instance.js'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
2026-01-06 16:23:17 +02:00
faBookmark as faBookmarkRegular,
faStar as faStarRegular,
} from '@fortawesome/free-regular-svg-icons'
import {
faBookmark,
faCheck,
faChevronRight,
faChevronUp,
2026-01-06 16:23:17 +02:00
faExternalLinkAlt,
faEyeSlash,
faHistory,
faMinus,
faPlus,
faReply,
faRetweet,
2026-01-06 16:23:17 +02:00
faShareAlt,
faSmileBeam,
2026-01-06 16:23:17 +02:00
faStar,
faThumbtack,
2026-01-06 16:23:17 +02:00
faTimes,
faWrench,
} from '@fortawesome/free-solid-svg-icons'
library.add(
faPlus,
faMinus,
faCheck,
faTimes,
faWrench,
faChevronRight,
faChevronUp,
faReply,
faRetweet,
faStar,
faStarRegular,
faSmileBeam,
faBookmark,
faBookmarkRegular,
faEyeSlash,
faThumbtack,
faShareAlt,
faExternalLinkAlt,
2026-01-06 16:22:52 +02:00
faHistory,
)
export default {
props: [
'button',
2025-01-14 09:59:03 +02:00
'status',
'extra',
'status',
'funcArg',
'getClass',
'getComponent',
'doAction',
2026-01-06 16:22:52 +02:00
'outerClose',
],
2026-01-06 16:22:52 +02:00
emits: ['interacted'],
components: {
StatusBookmarkFolderMenu,
2025-01-14 22:02:30 +02:00
EmojiPicker,
2026-01-06 16:22:52 +02:00
Popover,
},
2025-01-20 01:58:17 +02:00
data: () => ({
2026-01-06 16:22:52 +02:00
animationState: false,
2025-01-20 01:58:17 +02:00
}),
computed: {
2026-01-06 16:22:52 +02:00
buttonClass() {
return [
this.button.name + '-button',
{
'-with-extra': this.button.name === 'bookmark',
'-extra': this.extra,
2026-01-06 16:22:52 +02:00
'-quick': !this.extra,
},
]
},
2026-01-06 16:22:52 +02:00
userIsMuted() {
return this.$store.getters.relationship(this.status.user.id).muting
},
2026-01-06 16:22:52 +02:00
threadIsMuted() {
return this.status.thread_muted
},
2026-01-06 16:22:52 +02:00
hideCustomEmoji() {
return !useInstanceStore().pleromaCustomEmojiReactionsAvailable
2025-01-26 22:31:24 +02:00
},
2026-01-06 16:22:52 +02:00
buttonInnerClass() {
return [
this.button.name + '-button',
{
'main-button': this.extra,
'button-unstyled': !this.extra,
'-active': this.button.active?.(this.funcArg),
2026-01-06 16:22:52 +02:00
disabled: this.button.interactive
? !this.button.interactive(this.funcArg)
: false,
},
]
2025-01-21 10:45:11 +02:00
},
2026-01-06 16:22:52 +02:00
remoteInteractionLink() {
2026-01-29 13:44:33 +02:00
return useInstanceStore().getRemoteInteractionLink({
2026-01-06 16:22:52 +02:00
statusId: this.status.id,
})
},
2025-01-14 22:02:30 +02:00
},
methods: {
2026-01-06 16:22:52 +02:00
addReaction(event) {
2025-01-15 12:48:25 +02:00
const emoji = event.insertion
2026-01-06 16:22:52 +02:00
const existingReaction = this.status.emoji_reactions.find(
(r) => r.name === emoji,
)
2025-01-15 12:48:25 +02:00
if (existingReaction && existingReaction.me) {
this.$store.dispatch('unreactWithEmoji', { id: this.status.id, emoji })
} else {
this.$store.dispatch('reactWithEmoji', { id: this.status.id, emoji })
}
},
2026-01-06 17:32:22 +02:00
doActionWrap(
button,
close = () => {
/* no-op */
},
) {
2026-01-06 16:22:52 +02:00
if (
this.button.interactive ? !this.button.interactive(this.funcArg) : false
)
return
this.$emit('interacted')
2025-01-14 22:02:30 +02:00
if (button.name === 'emoji') {
this.$refs.picker.showPicker()
} else {
2025-01-20 01:58:17 +02:00
this.animationState = true
2025-01-14 22:02:30 +02:00
this.getComponent(button) === 'button' && this.doAction(button)
2025-01-20 01:58:17 +02:00
setTimeout(() => {
this.animationState = false
}, 500)
2025-01-18 19:31:20 +02:00
close()
2025-01-14 22:02:30 +02:00
}
2026-01-06 16:22:52 +02:00
},
},
}