use async clipboard API (#499)

This commit is contained in:
Nolan Lawson 2018-08-26 16:40:48 -07:00 committed by GitHub
parent 270df188cb
commit d49af06fbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 11 deletions

View file

@ -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)
}

View file

@ -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: {

View file

@ -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()
}
}
}