Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Clipboard changes #1759

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,40 @@ const SharingLink = ({ nonce, bucketEncryptionKey, refreshNonces }: Props) => {

const debouncedSwitchCopied = debounce(() => setCopied(false), 3000)


const onCopyInfo = useCallback(() => {
// this doesn't work on Mobile
// navigator.clipboard.writeText(link)
// .then(() => {
// setCopied(true)
// debouncedSwitchCopied()
// })
// .catch(console.error)
navigator.clipboard.writeText(link)
.then(() => {
setCopied(true)
debouncedSwitchCopied()
})
.catch(console.error)

//Create a textbox field where we can insert text to.
const copyFrom = document.createElement("textarea")
// //Create a textbox field where we can insert text to.
// const copyFrom = document.createElement("textarea")

//Set the text content to be the text you wished to copy.
copyFrom.textContent = link
// //Set the text content to be the text you wished to copy.
// copyFrom.textContent = link

//Append the textbox field into the body as a child.
//"execCommand()" only works when there exists selected text, and the text is inside
//document.body (meaning the text is part of a valid rendered HTML element).
document.body.appendChild(copyFrom)
// //Append the textbox field into the body as a child.
// //"execCommand()" only works when there exists selected text, and the text is inside
// //document.body (meaning the text is part of a valid rendered HTML element).
// document.body.appendChild(copyFrom)

//Select all the text!
copyFrom.select()
// //Select all the text!
// copyFrom.select()

//Execute command
document.execCommand("copy")
// //Execute command
// document.execCommand("copy")

//(Optional) De-select the text using blur().
copyFrom.blur()
// //(Optional) De-select the text using blur().
// copyFrom.blur()

//Remove the textbox field from the document.body, so no other JavaScript nor
//other elements can get access to this.
document.body.removeChild(copyFrom)
// //Remove the textbox field from the document.body, so no other JavaScript nor
// //other elements can get access to this.
// document.body.removeChild(copyFrom)

setCopied(true)
debouncedSwitchCopied()

}, [debouncedSwitchCopied, link])

const onDeleteNonce = useCallback(() => {
Expand Down