Skip to content

Commit

Permalink
update useCopyToClipboard to better fit our use case
Browse files Browse the repository at this point in the history
  • Loading branch information
avrohomgottlieb committed Sep 23, 2024
1 parent 9eab968 commit e021d2e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/src/components/CopyLinkButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const CopyLinkButton = ({computedFile}) => {
const [state, setState] = useState(states.unclicked)
const [downloadLink, setDownloadLink] = useState(null)

const [value, copyText] = useCopyToClipboard()
const copyText = useCopyToClipboard()
const { token } = useScPCAPortal()

const getDownloadLink = async () => {
Expand Down
7 changes: 1 addition & 6 deletions client/src/hooks/useCopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@
import { useState } from 'react'

Check failure on line 2 in client/src/hooks/useCopyToClipboard.js

View workflow job for this annotation

GitHub Actions / ESLint

client/src/hooks/useCopyToClipboard.js#L2

'useState' is defined but never used (no-unused-vars)

export const useCopyToClipboard = () => {
const [value, setValue] = useState(null)

const copyText = async (text) => {
if (!navigator?.clipboard) {
// eslint-disable-next-line no-console
console.warn('Clipboard not supported')

return false
}

try {
await navigator.clipboard.writeText(text)
setValue(text)

return true
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Copy failed', error)
setValue(null)

return false
}
}

return [value, copyText]
return copyText
}

0 comments on commit e021d2e

Please sign in to comment.