From 68093b627656af77d66b8f0b4805c05e36864295 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 16 Jan 2025 20:14:05 +0200 Subject: [PATCH] abstracted mute confirmation dialog into its own component. mutes in status actions work now --- src/components/confirm_modal/mute_confirm.js | 111 ++++++++++++++ src/components/confirm_modal/mute_confirm.vue | 58 +++++++ .../settings_modal/tabs/general_tab.vue | 10 ++ .../status_action_buttons/action_button.js | 7 +- .../action_button_container.js | 70 ++++++++- .../action_button_container.vue | 142 +++++++++++------- .../buttons_definitions.js | 5 - src/components/user_card/user_card.js | 31 +--- src/components/user_card/user_card.scss | 5 - src/components/user_card/user_card.vue | 50 +----- src/i18n/en.json | 2 + src/modules/config.js | 2 + src/modules/instance.js | 2 + 13 files changed, 356 insertions(+), 139 deletions(-) create mode 100644 src/components/confirm_modal/mute_confirm.js create mode 100644 src/components/confirm_modal/mute_confirm.vue diff --git a/src/components/confirm_modal/mute_confirm.js b/src/components/confirm_modal/mute_confirm.js new file mode 100644 index 000000000..62f8c3de3 --- /dev/null +++ b/src/components/confirm_modal/mute_confirm.js @@ -0,0 +1,111 @@ +import { unitToSeconds } from 'src/services/date_utils/date_utils.js' +import { mapGetters } from 'vuex' + +import ConfirmModal from './confirm_modal.vue' +import Select from 'src/components/select/select.vue' + +export default { + props: ['type', 'user'], + emits: ['hide', 'show', 'muted'], + data: () => ({ + showing: false, + muteExpiryAmount: 2, + muteExpiryUnit: 'hours' + }), + components: { + ConfirmModal, + Select + }, + computed: { + muteExpiryValue () { + unitToSeconds(this.muteExpiryUnit, this.muteExpiryAmount) + }, + muteExpiryUnits () { + return ['minutes', 'hours', 'days'] + }, + domain () { + return this.user.fqn.split('@')[1] + }, + keypath () { + if (this.type === 'domain') { + return 'status.mute_domain_confirm' + } else if (this.type === 'conversation') { + return 'status.mute_conversation_confirm' + } else { + return 'user_card.mute_confirm' + } + }, + userIsMuted () { + return this.$store.getters.relationship(this.user.id).muting + }, + conversationIsMuted () { + return this.status.conversation_muted + }, + domainIsMuted () { + return new Set(this.$store.state.users.currentUser.domainMutes).has(this.domain) + }, + shouldConfirm () { + switch (this.type) { + case 'domain': { + return this.mergedConfig.modalOnMuteDomain + } + case 'conversation': { + return this.mergedConfig.modalOnMuteConversation + } + default: { + return this.mergedConfig.modalOnMute + } + } + }, + ...mapGetters(['mergedConfig']) + }, + methods: { + optionallyPrompt () { + console.log('Triggered') + if (this.shouldConfirm) { + console.log('SHAWN!!') + this.show() + } else { + this.doMute() + } + }, + show () { + this.showing = true + this.$emit('show') + }, + hide () { + this.showing = false + this.$emit('hide') + }, + doMute () { + switch (this.type) { + case 'domain': { + if (!this.domainIsMuted) { + this.$store.dispatch('muteDomain', { id: this.domain, expiresIn: this.muteExpiryValue }) + } else { + this.$store.dispatch('unmuteDomain', { id: this.domain }) + } + break + } + case 'conversation': { + if (!this.conversationIsMuted) { + this.$store.dispatch('muteConversation', { id: this.status.id, expiresIn: this.muteExpiryValue }) + } else { + this.$store.dispatch('unmuteConversation', { id: this.status.id }) + } + break + } + default: { + if (!this.userIsMuted) { + this.$store.dispatch('muteUser', { id: this.user.id, expiresIn: this.muteExpiryValue }) + } else { + this.$store.dispatch('unmuteUser', { id: this.user.id }) + } + break + } + } + this.$emit('muted') + this.hide() + } + } +} diff --git a/src/components/confirm_modal/mute_confirm.vue b/src/components/confirm_modal/mute_confirm.vue new file mode 100644 index 000000000..c55d11519 --- /dev/null +++ b/src/components/confirm_modal/mute_confirm.vue @@ -0,0 +1,58 @@ + + +