abstracted mute confirmation dialog into its own component. mutes in status actions work now
This commit is contained in:
parent
41f54b687b
commit
68093b6276
13 changed files with 356 additions and 139 deletions
111
src/components/confirm_modal/mute_confirm.js
Normal file
111
src/components/confirm_modal/mute_confirm.js
Normal file
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/components/confirm_modal/mute_confirm.vue
Normal file
58
src/components/confirm_modal/mute_confirm.vue
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<confirm-modal
|
||||
v-if="showing"
|
||||
:title="$t('user_card.mute_confirm_title')"
|
||||
:confirm-text="$t('user_card.mute_confirm_accept_button')"
|
||||
:cancel-text="$t('user_card.mute_confirm_cancel_button')"
|
||||
@accepted="doMute"
|
||||
@cancelled="hide"
|
||||
>
|
||||
<i18n-t
|
||||
:keypath="keypath"
|
||||
tag="div"
|
||||
>
|
||||
<template #domain>
|
||||
<span v-text="domain" />
|
||||
</template>
|
||||
<template #user>
|
||||
<span v-text="user.screen_name_ui" />
|
||||
</template>
|
||||
</i18n-t>
|
||||
<div class="mute-expiry" v-if="type !== 'domain'">
|
||||
<p>
|
||||
<label>
|
||||
{{ $t('user_card.mute_duration_prompt') }}
|
||||
</label>
|
||||
<input
|
||||
v-model="muteExpiryAmount"
|
||||
type="number"
|
||||
class="input expiry-amount hide-number-spinner"
|
||||
:min="0"
|
||||
>
|
||||
{{ ' ' }}
|
||||
<Select
|
||||
v-model="muteExpiryUnit"
|
||||
unstyled="true"
|
||||
class="expiry-unit"
|
||||
>
|
||||
<option
|
||||
v-for="unit in muteExpiryUnits"
|
||||
:key="unit"
|
||||
:value="unit"
|
||||
>
|
||||
{{ $t(`time.unit.${unit}_short`, ['']) }}
|
||||
</option>
|
||||
</Select>
|
||||
</p>
|
||||
</div>
|
||||
</confirm-modal>
|
||||
</template>
|
||||
|
||||
<script src="./mute_confirm.js" />
|
||||
|
||||
<style lang="scss">
|
||||
.expiry-amount {
|
||||
width: 4em;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue