mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
clipboard implemented with react hooks, fix #58
This commit is contained in:
@@ -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)}`)
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user