use computed instead of methods when possible

This commit is contained in:
Henry Jameson 2025-01-11 18:01:53 +02:00
parent fe84a52dcc
commit 08f8b975b6
2 changed files with 27 additions and 24 deletions

View file

@ -233,14 +233,12 @@ const BUTTONS = [{
Object.entries(button).map(([k, v]) => [k, typeof v === 'function' ? v : () => v]) Object.entries(button).map(([k, v]) => [k, typeof v === 'function' ? v : () => v])
) )
}) })
console.log(BUTTONS)
const StatusActionButtons = { const StatusActionButtons = {
props: ['status', 'replying'], props: ['status', 'replying'],
emits: ['toggleReplying'], emits: ['toggleReplying'],
data () { data () {
return { return {
buttons: BUTTONS,
showingConfirmDialog: false, showingConfirmDialog: false,
currentConfirmTitle: '', currentConfirmTitle: '',
currentConfirmOkText: '', currentConfirmOkText: '',
@ -251,6 +249,24 @@ const StatusActionButtons = {
components: { components: {
ConfirmModal ConfirmModal
}, },
computed: {
buttons () {
return BUTTONS.filter(x => x.if(this.funcArg))
},
funcArg () {
return {
status: this.status,
replying: this.replying,
emit: this.$emit,
dispatch: this.$store.dispatch,
state: this.$store.state,
getters: this.$store.getters,
router: this.$router,
currentUser: this.$store.state.users.currentUser,
loggedIn: !!this.$store.state.users.currentUser
}
}
},
methods: { methods: {
doAction (button) { doAction (button) {
this.doActionReal(button) this.doActionReal(button)
@ -269,19 +285,6 @@ const StatusActionButtons = {
return 'button' return 'button'
} }
}, },
funcArg () {
return {
status: this.status,
replying: this.replying,
emit: this.$emit,
dispatch: this.$store.dispatch,
state: this.$store.state,
getters: this.$store.getters,
router: this.$router,
currentUser: this.$store.state.users.currentUser,
loggedIn: !!this.$store.state.users.currentUser
}
},
getClass (button) { getClass (button) {
return { return {
[button.name() + '-button']: true, [button.name() + '-button']: true,

View file

@ -4,7 +4,7 @@
<span <span
class="quick-action" class="quick-action"
v-for="button in buttons" v-for="button in buttons"
:key="button.name()" :key="button.name"
> >
<component <component
:is="component(button)" :is="component(button)"
@ -12,24 +12,24 @@
:class="getClass(button)" :class="getClass(button)"
role="button" role="button"
:tabindex="0" :tabindex="0"
:title="$t(button.label(funcArg()))" :title="$t(button.label(funcArg))"
@click.stop="component(button) === 'button' && doAction(button)" @click.stop="component(button) === 'button' && doAction(button)"
:href="component(button) == 'a' ? button.link?.(funcArg()) || getRemoteInteractionLink : undefined" :href="component(button) == 'a' ? button.link?.(funcArg) || getRemoteInteractionLink : undefined"
> >
<FALayers class="fa-old-padding"> <FALayers class="fa-old-padding">
<FAIcon <FAIcon
class="fa-scale-110" class="fa-scale-110"
:icon="button.icon(funcArg())" :icon="button.icon(funcArg)"
/> />
<template v-if="button.toggleable?.(funcArg()) && button.active"> <template v-if="button.toggleable?.(funcArg) && button.active">
<FAIcon <FAIcon
v-show="!button.active(funcArg())" v-show="!button.active(funcArg)"
class="focus-marker" class="focus-marker"
transform="shrink-6 up-9 right-17" transform="shrink-6 up-9 right-17"
icon="plus" icon="plus"
/> />
<FAIcon <FAIcon
v-show="button.active(funcArg())" v-show="button.active(funcArg)"
class="focus-marker" class="focus-marker"
transform="shrink-6 up-9 right-17" transform="shrink-6 up-9 right-17"
icon="times" icon="times"
@ -39,9 +39,9 @@
</component> </component>
<span <span
class="action-counter" class="action-counter"
v-if="button.counter?.(funcArg()) > 0" v-if="button.counter?.(funcArg) > 0"
> >
{{ button.counter?.(funcArg()) }} {{ button.counter?.(funcArg) }}
</span> </span>
</span> </span>
</span> </span>