feat: add confirm for account handle (#1126)

This commit is contained in:
webfansplz 2023-01-15 16:33:55 +08:00 committed by GitHub
parent 274e182bdf
commit eb1f769e32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 19 deletions

View file

@ -9,9 +9,16 @@ let relationship = $(useRelationship(account))
const isSelf = $(useSelfAccount(() => account)) const isSelf = $(useSelfAccount(() => account))
const { t } = useI18n()
const masto = useMasto() const masto = useMasto()
const toggleMute = async () => {
// TODO: Add confirmation const isConfirmed = async (title: string) => {
return await openConfirmDialog(t('common.confirm_dialog.title', [title])) === 'confirm'
}
const toggleMute = async (title: string) => {
if (!await isConfirmed(title))
return
relationship!.muting = !relationship!.muting relationship!.muting = !relationship!.muting
relationship = relationship!.muting relationship = relationship!.muting
@ -21,22 +28,25 @@ const toggleMute = async () => {
: await masto.v1.accounts.unmute(account.id) : await masto.v1.accounts.unmute(account.id)
} }
const toggleBlockUser = async () => { const toggleBlockUser = async (title: string) => {
// TODO: Add confirmation if (!await isConfirmed(title))
return
relationship!.blocking = !relationship!.blocking relationship!.blocking = !relationship!.blocking
relationship = await masto.v1.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id) relationship = await masto.v1.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id)
} }
const toggleBlockDomain = async () => { const toggleBlockDomain = async (title: string) => {
// TODO: Add confirmation if (!await isConfirmed(title))
return
relationship!.domainBlocking = !relationship!.domainBlocking relationship!.domainBlocking = !relationship!.domainBlocking
await masto.v1.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account)) await masto.v1.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account))
} }
const toggleReblogs = async () => { const toggleReblogs = async (title: string) => {
// TODO: Add confirmation if (!await isConfirmed(title))
return
const showingReblogs = !relationship?.showingReblogs const showingReblogs = !relationship?.showingReblogs
relationship = await masto.v1.accounts.follow(account.id, { reblogs: showingReblogs }) relationship = await masto.v1.accounts.follow(account.id, { reblogs: showingReblogs })
@ -80,14 +90,14 @@ const toggleReblogs = async () => {
icon="i-ri:repeat-line" icon="i-ri:repeat-line"
:text="$t('menu.show_reblogs', [`@${account.acct}`])" :text="$t('menu.show_reblogs', [`@${account.acct}`])"
:command="command" :command="command"
@click="toggleReblogs" @click="toggleReblogs($t('menu.show_reblogs', [`@${account.acct}`]))"
/> />
<CommonDropdownItem <CommonDropdownItem
v-else v-else
:text="$t('menu.hide_reblogs', [`@${account.acct}`])" :text="$t('menu.hide_reblogs', [`@${account.acct}`])"
icon="i-ri:repeat-line" icon="i-ri:repeat-line"
:command="command" :command="command"
@click="toggleReblogs" @click="toggleReblogs($t('menu.hide_reblogs', [`@${account.acct}`]))"
/> />
<CommonDropdownItem <CommonDropdownItem
@ -95,14 +105,14 @@ const toggleReblogs = async () => {
:text="$t('menu.mute_account', [`@${account.acct}`])" :text="$t('menu.mute_account', [`@${account.acct}`])"
icon="i-ri:volume-up-fill" icon="i-ri:volume-up-fill"
:command="command" :command="command"
@click="toggleMute" @click="toggleMute($t('menu.mute_account', [`@${account.acct}`]))"
/> />
<CommonDropdownItem <CommonDropdownItem
v-else v-else
:text="$t('menu.unmute_account', [`@${account.acct}`])" :text="$t('menu.unmute_account', [`@${account.acct}`])"
icon="i-ri:volume-mute-line" icon="i-ri:volume-mute-line"
:command="command" :command="command"
@click="toggleMute" @click="toggleMute($t('menu.unmute_account', [`@${account.acct}`]))"
/> />
<CommonDropdownItem <CommonDropdownItem
@ -110,14 +120,14 @@ const toggleReblogs = async () => {
:text="$t('menu.block_account', [`@${account.acct}`])" :text="$t('menu.block_account', [`@${account.acct}`])"
icon="i-ri:forbid-2-line" icon="i-ri:forbid-2-line"
:command="command" :command="command"
@click="toggleBlockUser" @click="toggleBlockUser($t('menu.block_account', [`@${account.acct}`]))"
/> />
<CommonDropdownItem <CommonDropdownItem
v-else v-else
:text="$t('menu.unblock_account', [`@${account.acct}`])" :text="$t('menu.unblock_account', [`@${account.acct}`])"
icon="i-ri:checkbox-circle-line" icon="i-ri:checkbox-circle-line"
:command="command" :command="command"
@click="toggleBlockUser" @click="toggleBlockUser($t('menu.unblock_account', [`@${account.acct}`]))"
/> />
<template v-if="getServerName(account) !== currentServer"> <template v-if="getServerName(account) !== currentServer">
@ -126,14 +136,14 @@ const toggleReblogs = async () => {
:text="$t('menu.block_domain', [getServerName(account)])" :text="$t('menu.block_domain', [getServerName(account)])"
icon="i-ri:shut-down-line" icon="i-ri:shut-down-line"
:command="command" :command="command"
@click="toggleBlockDomain" @click="toggleBlockDomain($t('menu.block_domain', [getServerName(account)]))"
/> />
<CommonDropdownItem <CommonDropdownItem
v-else v-else
:text="$t('menu.unblock_domain', [getServerName(account)])" :text="$t('menu.unblock_domain', [getServerName(account)])"
icon="i-ri:restart-line" icon="i-ri:restart-line"
:command="command" :command="command"
@click="toggleBlockDomain" @click="toggleBlockDomain($t('menu.unblock_domain', [getServerName(account)]))"
/> />
</template> </template>
</template> </template>

View file

@ -91,7 +91,7 @@
"confirm_dialog": { "confirm_dialog": {
"cancel": "No", "cancel": "No",
"confirm": "Yes", "confirm": "Yes",
"title": "Are you sure?" "title": "Are you sure {0}?"
}, },
"end_of_list": "End of the list", "end_of_list": "End of the list",
"error": "ERROR", "error": "ERROR",

View file

@ -88,7 +88,7 @@
"confirm_dialog": { "confirm_dialog": {
"cancel": "否", "cancel": "否",
"confirm": "是", "confirm": "是",
"title": "你确定吗?" "title": "你确定 {0} 吗?"
}, },
"end_of_list": "列表到底啦", "end_of_list": "列表到底啦",
"error": "错误", "error": "错误",

View file

@ -91,7 +91,7 @@
"confirm_dialog": { "confirm_dialog": {
"cancel": "否", "cancel": "否",
"confirm": "是", "confirm": "是",
"title": "你確定嗎?" "title": "你確定 {0} 嗎?"
}, },
"end_of_list": "清單到底啦", "end_of_list": "清單到底啦",
"error": "錯誤", "error": "錯誤",