From e00e4074e18b9d83b2072041c522de6c79291d0c Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Tue, 14 Nov 2023 23:34:56 +0900 Subject: [PATCH] feat: put account name copy button (#2347) --- components/account/AccountHeader.vue | 28 +++++++++++++++++++++++++++- locales/en.json | 1 + locales/ja-JP.json | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/components/account/AccountHeader.vue b/components/account/AccountHeader.vue index b9534fbd..85d2cfe5 100644 --- a/components/account/AccountHeader.vue +++ b/components/account/AccountHeader.vue @@ -22,6 +22,7 @@ const namedFields = ref([]) const iconFields = ref([]) const isEditingPersonalNote = ref(false) const hasHeader = $computed(() => !account.header.endsWith('/original/missing.png')) +const isCopied = ref(false) function getFieldIconTitle(fieldName: string) { return fieldName === 'Joined' ? t('account.joined') : fieldName @@ -105,6 +106,23 @@ const isSelf = $(useSelfAccount(() => account)) const isNotifiedOnPost = $computed(() => !!relationship?.notifying) const personalNoteMaxLength = 2000 + +async function copyAccountName() { + try { + const shortHandle = getShortHandle(account) + const serverName = getServerName(account) + const accountName = `${shortHandle}@${serverName}` + await navigator.clipboard.writeText(accountName) + } + catch (err) { + console.error('Failed to copy account name:', err) + } + + isCopied.value = true + setTimeout(() => { + isCopied.value = false + }, 2000) +}