onedrive/components/DownloadBtn.tsx

47 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-06-25 14:15:00 +00:00
import { FunctionComponent } from 'react'
2021-06-29 20:00:05 +00:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import toast, { Toaster } from 'react-hot-toast'
import { useRouter } from 'next/router'
import { useClipboard } from 'use-clipboard-copy'
2021-06-29 20:00:05 +00:00
import { getBaseUrl } from '../utils/tools'
2021-06-25 14:15:00 +00:00
const DownloadBtn: FunctionComponent<{ downloadUrl: string }> = ({ downloadUrl }) => {
2021-06-29 20:00:05 +00:00
const { asPath } = useRouter()
const clipboard = useClipboard()
2021-06-29 20:00:05 +00:00
2021-06-25 14:15:00 +00:00
return (
2021-06-29 20:00:05 +00:00
<div className="flex flex-wrap space-x-2 justify-center">
2021-08-29 21:31:42 +00:00
<Toaster
toastOptions={{
style: {
background: '#316C23',
color: '#ffffff',
},
}}
/>
2021-06-25 14:15:00 +00:00
<a
2021-06-29 20:00:05 +00:00
className="flex-shrink-0 w-36 flex space-x-4 items-center justify-center bg-blue-500 rounded py-2 px-4 text-white focus:outline-none focus:ring focus:ring-blue-300 hover:bg-blue-600 mb-2"
2021-06-25 14:15:00 +00:00
href={downloadUrl}
target="_blank"
rel="noopener noreferrer"
>
<FontAwesomeIcon icon="file-download" />
<span>Download</span>
</a>
2021-06-29 20:00:05 +00:00
<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={() => {
clipboard.copy(`${getBaseUrl()}/api?path=${asPath}&raw=true`)
2021-06-29 20:00:05 +00:00
toast.success('Copied direct link to clipboard.')
}}
>
<FontAwesomeIcon icon="copy" />
<span>Copy direct link</span>
</button>
2021-06-25 14:15:00 +00:00
</div>
)
}
export default DownloadBtn