From 08f8b975b68212dc2ff7616c1b3c163402327a6a Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sat, 11 Jan 2025 18:01:53 +0200 Subject: [PATCH] use computed instead of methods when possible --- .../status_action_buttons.js | 33 ++++++++++--------- .../status_action_buttons.vue | 18 +++++----- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/components/status_action_buttons/status_action_buttons.js b/src/components/status_action_buttons/status_action_buttons.js index 2a7c70a41..52e3b3f8b 100644 --- a/src/components/status_action_buttons/status_action_buttons.js +++ b/src/components/status_action_buttons/status_action_buttons.js @@ -233,14 +233,12 @@ const BUTTONS = [{ Object.entries(button).map(([k, v]) => [k, typeof v === 'function' ? v : () => v]) ) }) -console.log(BUTTONS) const StatusActionButtons = { props: ['status', 'replying'], emits: ['toggleReplying'], data () { return { - buttons: BUTTONS, showingConfirmDialog: false, currentConfirmTitle: '', currentConfirmOkText: '', @@ -251,6 +249,24 @@ const StatusActionButtons = { components: { 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: { doAction (button) { this.doActionReal(button) @@ -269,19 +285,6 @@ const StatusActionButtons = { 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) { return { [button.name() + '-button']: true, diff --git a/src/components/status_action_buttons/status_action_buttons.vue b/src/components/status_action_buttons/status_action_buttons.vue index 3950e22db..b779ea46b 100644 --- a/src/components/status_action_buttons/status_action_buttons.vue +++ b/src/components/status_action_buttons/status_action_buttons.vue @@ -4,7 +4,7 @@ -