use async/await for copy to clipboard action
This commit is contained in:
parent
8a11fcfd06
commit
363142414b
|
@ -421,7 +421,7 @@ const showNotificationHandler = action => {
|
||||||
|
|
||||||
const promptUserHandler = () => {}
|
const promptUserHandler = () => {}
|
||||||
|
|
||||||
const copyToClipboardHandler = action => {
|
const copyToClipboardHandler = async action => {
|
||||||
const { textToCopy, showNotification, notificationMessage } =
|
const { textToCopy, showNotification, notificationMessage } =
|
||||||
action.parameters
|
action.parameters
|
||||||
|
|
||||||
|
@ -429,18 +429,16 @@ const copyToClipboardHandler = action => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
navigator.clipboard
|
try {
|
||||||
.writeText(textToCopy)
|
await navigator.clipboard.writeText(textToCopy)
|
||||||
.then(() => {
|
if (showNotification) {
|
||||||
if (showNotification) {
|
const message = notificationMessage || "Copied to clipboard"
|
||||||
const message = notificationMessage || "Copied to clipboard"
|
notificationStore.actions.success(message, true, 3000)
|
||||||
notificationStore.actions.success(message, true, 3000)
|
}
|
||||||
}
|
} catch (err) {
|
||||||
})
|
console.error("Failed to copy text: ", err)
|
||||||
.catch(err => {
|
notificationStore.actions.error("Failed to copy to clipboard")
|
||||||
console.error("Failed to copy text: ", err)
|
}
|
||||||
notificationStore.actions.error("Failed to copy to clipboard")
|
|
||||||
})
|
|
||||||
|
|
||||||
return { copied: textToCopy }
|
return { copied: textToCopy }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue