clipboard implemented with react hooks, fix #58

This commit is contained in:
spencerwooo
2021-08-23 15:02:06 +01:00
parent 778666b7b4
commit 96e9dbb2b2
5 changed files with 56 additions and 8 deletions
+3 -4
View File
@@ -2,6 +2,7 @@ import axios from 'axios'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import toast, { Toaster } from 'react-hot-toast'
import emojiRegex from 'emoji-regex'
import { useClipboard } from 'use-clipboard-copy'
import { ParsedUrlQuery } from 'querystring'
import { FunctionComponent, useState } from 'react'
@@ -105,6 +106,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
const [activeImageIdx, setActiveImageIdx] = useState(0)
const router = useRouter()
const clipboard = useClipboard()
const path = queryToPath(query)
@@ -204,9 +206,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
key: 'copy',
render: <FontAwesomeIcon icon="copy" />,
onClick: i => {
navigator.clipboard.writeText(
i.alt ? `${getBaseUrl()}/api?path=${path + '/' + i.alt}&raw=true` : ''
)
clipboard.copy(i.alt ? `${getBaseUrl()}/api?path=${path + '/' + i.alt}&raw=true` : '')
toast.success('Copied image permanent link to clipboard.')
},
},
@@ -225,7 +225,6 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
setActiveImageIdx(imageIndexDict[c.id])
setImageViewerVisibility(true)
} else {
console.log(path)
router.push(`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`)
}
}}