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 -1
View File
@@ -2,6 +2,7 @@ import { FunctionComponent } from 'react'
import ReactPlayer from 'react-player'
import Image from 'next/image'
import { useRouter } from 'next/router'
import { useClipboard } from 'use-clipboard-copy'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import toast, { Toaster } from 'react-hot-toast'
@@ -9,6 +10,7 @@ import { getBaseUrl } from '../../utils/tools'
export const VideoPreview: FunctionComponent<{ file: any }> = ({ file }) => {
const { asPath } = useRouter()
const clipboard = useClipboard()
return (
<>
@@ -40,7 +42,7 @@ export const VideoPreview: FunctionComponent<{ file: any }> = ({ file }) => {
<button
className="flex-shrink-0 w-48 flex space-x-4 items-center justify-center bg-yellow-500 rounded py-2 px-4 text-white focus:outline-none focus:ring focus:ring-yellow-300 hover:bg-yellow-600 mb-2"
onClick={() => {
navigator.clipboard.writeText(`${getBaseUrl()}/api?path=${asPath}&raw=true`)
clipboard.copy(`${getBaseUrl()}/api?path=${asPath}&raw=true`)
toast.success('Copied direct link to clipboard.')
}}
>