|
1 | | -import { FileJson, DownloadCloud } from 'lucide-react'; |
| 1 | +import { FileJson, DownloadCloud, Copy, ExternalLink } from 'lucide-react'; |
| 2 | +import { useClipboard } from '../hooks/use-clipboard'; |
| 3 | +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'; |
| 4 | +import { useState } from 'react'; |
2 | 5 |
|
3 | 6 | interface Props { |
4 | 7 | webpage_url: string; |
5 | 8 | repo: string; |
6 | 9 | } |
7 | 10 |
|
8 | 11 | const FormulaLinks = ({ webpage_url, repo }: Props) => { |
| 12 | + const { copy } = useClipboard(); |
| 13 | + const [jsonCopied, setJsonCopied] = useState(false); |
| 14 | + const [downloadCopied, setDownloadCopied] = useState(false); |
9 | 15 | const jsonApiUrl = `${webpage_url}/raw.json`; |
10 | 16 |
|
11 | 17 | const [, , , , ...dataf] = webpage_url.split("/"); |
12 | | - |
13 | 18 | const downloadUrl = new URL(`/dl/${dataf.join("/")}/raw.dl`, window.location.origin); |
14 | 19 |
|
| 20 | + const handleJsonCopy = () => { |
| 21 | + copy(jsonApiUrl); |
| 22 | + setJsonCopied(true); |
| 23 | + setTimeout(() => setJsonCopied(false), 2000); |
| 24 | + }; |
| 25 | + |
| 26 | + const handleDownloadCopy = () => { |
| 27 | + copy(downloadUrl.toString()); |
| 28 | + setDownloadCopied(true); |
| 29 | + setTimeout(() => setDownloadCopied(false), 2000); |
| 30 | + }; |
| 31 | + |
15 | 32 | return ( |
16 | | - <div className="grid gap-3 p-4 bg-blue-50/30 dark:bg-blue-950/30 rounded-lg border border-blue-100 dark:border-blue-900"> |
17 | | - <div className="space-y-2"> |
18 | | - <h2 className="text-sm font-medium text-blue-700/70 dark:text-blue-300/70">Package Links</h2> |
19 | | - <div className="grid gap-2"> |
20 | | - <a |
21 | | - href={jsonApiUrl} |
22 | | - target="_blank" |
23 | | - rel="noreferrer" |
24 | | - className="flex items-center gap-3 w-full group" |
25 | | - > |
26 | | - <FileJson className="h-5 w-5 transition-transform duration-200 text-blue-600/70 dark:text-blue-400/70 group-hover:scale-110" /> |
27 | | - <div className="flex flex-col items-start"> |
28 | | - <span className="text-sm font-medium text-gray-700 dark:text-gray-300">JSON API</span> |
29 | | - <code className="text-xs text-gray-500 dark:text-gray-400 font-mono"> |
30 | | - {`${webpage_url}/raw.json`} |
31 | | - </code> |
| 33 | + <TooltipProvider delayDuration={0}> |
| 34 | + <div className="grid gap-3 p-4 bg-blue-50/30 dark:bg-blue-950/30 rounded-lg border border-blue-100 dark:border-blue-900"> |
| 35 | + <div className="space-y-2"> |
| 36 | + <h2 className="text-sm font-medium text-blue-700/70 dark:text-blue-300/70">Package Links</h2> |
| 37 | + <div className="grid gap-3"> |
| 38 | + <div className="flex items-center gap-3 w-full group"> |
| 39 | + <FileJson className="h-5 w-5 text-blue-600/70 dark:text-blue-400/70" /> |
| 40 | + <div className="flex flex-col items-start gap-1 flex-1"> |
| 41 | + <span className="text-sm font-medium">JSON API</span> |
| 42 | + <div className="flex items-center gap-2 w-full"> |
| 43 | + <Tooltip open={jsonCopied}> |
| 44 | + <TooltipTrigger asChild> |
| 45 | + <button |
| 46 | + onClick={handleJsonCopy} |
| 47 | + className="flex items-center gap-2 px-3 py-1.5 rounded-md bg-blue-50 dark:bg-blue-950 hover:bg-blue-100 dark:hover:bg-blue-900 text-blue-600 dark:text-blue-400 transition-colors flex-1" |
| 48 | + > |
| 49 | + <code className="text-xs font-mono">{jsonApiUrl}</code> |
| 50 | + <Copy className="h-4 w-4 shrink-0" /> |
| 51 | + </button> |
| 52 | + </TooltipTrigger> |
| 53 | + <TooltipContent> |
| 54 | + <p>Copied!</p> |
| 55 | + </TooltipContent> |
| 56 | + </Tooltip> |
| 57 | + |
| 58 | + <a |
| 59 | + href={jsonApiUrl} |
| 60 | + target="_blank" |
| 61 | + rel="noreferrer" |
| 62 | + className="px-3 py-1.5 rounded-md bg-blue-600 hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-600 text-white transition-colors flex items-center gap-2" |
| 63 | + > |
| 64 | + <span className="text-xs">Open</span> |
| 65 | + <ExternalLink className="h-4 w-4" /> |
| 66 | + </a> |
| 67 | + </div> |
| 68 | + </div> |
32 | 69 | </div> |
33 | | - </a> |
34 | | - |
35 | | - {repo != "soarpkgs" && <a |
36 | | - href={downloadUrl.toString()} |
37 | | - target="_blank" |
38 | | - rel="noreferrer" |
39 | | - className="flex items-center gap-3 w-full group" |
40 | | - > |
41 | | - <DownloadCloud className="h-5 w-5 text-blue-600/70 dark:text-blue-400/70 group-hover:scale-110 transition-transform duration-200" /> |
42 | | - <div className="flex flex-col items-start"> |
43 | | - <span className="text-sm font-medium text-gray-700 dark:text-gray-300">Download</span> |
44 | | - <code className="text-xs text-gray-500 dark:text-gray-400 font-mono"> |
45 | | - https://pkgs.pkgforge.dev/dl/{`${dataf.join("/")}/raw.dl`} |
46 | | - </code> |
47 | | - </div> |
48 | | - </a>} |
| 70 | + |
| 71 | + {repo != "soarpkgs" && ( |
| 72 | + <div className="flex items-center gap-3 w-full group"> |
| 73 | + <DownloadCloud className="h-5 w-5 text-blue-600/70 dark:text-blue-400/70" /> |
| 74 | + <div className="flex flex-col items-start gap-1 flex-1"> |
| 75 | + <span className="text-sm font-medium">Download URL</span> |
| 76 | + <div className="flex items-center gap-2 w-full"> |
| 77 | + <Tooltip open={downloadCopied}> |
| 78 | + <TooltipTrigger asChild> |
| 79 | + <button |
| 80 | + onClick={handleDownloadCopy} |
| 81 | + className="flex items-center gap-2 px-3 py-1.5 rounded-md bg-blue-50 dark:bg-blue-950 hover:bg-blue-100 dark:hover:bg-blue-900 text-blue-600 dark:text-blue-400 transition-colors flex-1" |
| 82 | + > |
| 83 | + <code className="text-xs font-mono">{downloadUrl.toString()}</code> |
| 84 | + <Copy className="h-4 w-4 shrink-0" /> |
| 85 | + </button> |
| 86 | + </TooltipTrigger> |
| 87 | + <TooltipContent> |
| 88 | + <p>Copied!</p> |
| 89 | + </TooltipContent> |
| 90 | + </Tooltip> |
| 91 | + |
| 92 | + <a |
| 93 | + href={downloadUrl.toString()} |
| 94 | + target="_blank" |
| 95 | + rel="noreferrer" |
| 96 | + className="px-3 py-1.5 rounded-md bg-blue-600 hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-600 text-white transition-colors flex items-center gap-2" |
| 97 | + > |
| 98 | + <span className="text-xs">Download</span> |
| 99 | + <ExternalLink className="h-4 w-4" /> |
| 100 | + </a> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + )} |
| 105 | + </div> |
49 | 106 | </div> |
50 | 107 | </div> |
51 | | - </div> |
| 108 | + </TooltipProvider> |
52 | 109 | ); |
53 | 110 | }; |
54 | 111 |
|
|
0 commit comments