diff --git a/routes/_actions/copyText.js b/routes/_actions/copyText.js new file mode 100644 index 00000000..f6e9bfdc --- /dev/null +++ b/routes/_actions/copyText.js @@ -0,0 +1,17 @@ +import { importShowCopyDialog } from '../_components/dialog/asyncDialogs' +import { toast } from '../_utils/toast' + +export async function copyText (text) { + if (navigator.clipboard) { // not supported in all browsers + try { + await navigator.clipboard.writeText(text) + toast.say('Copied to clipboard') + return + } catch (e) { + console.error(e) + } + } + + let showCopyDialog = await importShowCopyDialog() + showCopyDialog(text) +} diff --git a/routes/_components/dialog/components/AccountProfileOptionsDialog.html b/routes/_components/dialog/components/AccountProfileOptionsDialog.html index 5f415970..ec249767 100644 --- a/routes/_components/dialog/components/AccountProfileOptionsDialog.html +++ b/routes/_components/dialog/components/AccountProfileOptionsDialog.html @@ -10,7 +10,7 @@ import ModalDialog from './ModalDialog.html' import { store } from '../../../_store/store' import GenericDialogList from './GenericDialogList.html' -import { importShowComposeDialog, importShowCopyDialog } from '../asyncDialogs' +import { importShowComposeDialog } from '../asyncDialogs' import { createDialogId } from '../helpers/createDialogId' import { show } from '../helpers/showDialog' import { close } from '../helpers/closeDialog' @@ -20,6 +20,7 @@ import { setAccountMuted } from '../../../_actions/mute' import { setAccountFollowed } from '../../../_actions/follow' import { setShowReblogs } from '../../../_actions/setShowReblogs' import { setDomainBlocked } from '../../../_actions/setDomainBlocked' +import { copyText } from '../../../_actions/copyText' export default { oncreate, @@ -175,8 +176,8 @@ export default { async onCopyClicked () { let { account } = this.get() let { url } = account - let showCopyDialog = await importShowCopyDialog() - showCopyDialog(url) + this.close() + await copyText(url) } }, components: { diff --git a/routes/_components/dialog/components/StatusOptionsDialog.html b/routes/_components/dialog/components/StatusOptionsDialog.html index 91e6257e..e927dbfe 100644 --- a/routes/_components/dialog/components/StatusOptionsDialog.html +++ b/routes/_components/dialog/components/StatusOptionsDialog.html @@ -18,8 +18,8 @@ import { oncreate } from '../helpers/onCreateDialog' import { setAccountBlocked } from '../../../_actions/block' import { setAccountMuted } from '../../../_actions/mute' import { setStatusPinnedOrUnpinned } from '../../../_actions/pin' -import { importShowCopyDialog } from '../asyncDialogs' import { setConversationMuted } from '../../../_actions/muteConversation' +import { copyText } from '../../../_actions/copyText' export default { oncreate, @@ -162,17 +162,16 @@ export default { this.close() await setAccountMuted(accountId, !muting, true) }, - async onCopyClicked () { - let { status } = this.get() - let { url } = status - let showCopyDialog = await importShowCopyDialog() - this.close() - showCopyDialog(url) - }, async onMuteConversationClicked () { let { statusId, mutingConversation } = this.get() this.close() await setConversationMuted(statusId, !mutingConversation, true) + }, + async onCopyClicked () { + let { status } = this.get() + let { url } = status + await copyText(url) + this.close() } } }