mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-17 01:23:39 -05:00
Add copy pull command button to image info
This commit is contained in:
@@ -8,8 +8,10 @@ import {
|
|||||||
import {
|
import {
|
||||||
IconAlertTriangleFilled,
|
IconAlertTriangleFilled,
|
||||||
IconArrowUpRight,
|
IconArrowUpRight,
|
||||||
|
IconCheck,
|
||||||
IconCircleArrowUpFilled,
|
IconCircleArrowUpFilled,
|
||||||
IconCircleCheckFilled,
|
IconCircleCheckFilled,
|
||||||
|
IconCopy,
|
||||||
IconCube,
|
IconCube,
|
||||||
IconHelpCircleFilled,
|
IconHelpCircleFilled,
|
||||||
IconStopwatch,
|
IconStopwatch,
|
||||||
@@ -28,12 +30,23 @@ const clickable_registries = [
|
|||||||
|
|
||||||
export default function Image({ data }: { data: Image }) {
|
export default function Image({ data }: { data: Image }) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [copySuccess, setCopySuccess] = useState(false);
|
||||||
const handleOpen = () => {
|
const handleOpen = () => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
};
|
};
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
const handleCopy = (text: string) => {
|
||||||
|
return () => {
|
||||||
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
|
setCopySuccess(true);
|
||||||
|
setTimeout(() => {
|
||||||
|
setCopySuccess(false);
|
||||||
|
}, 3000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
var url: string | null = null;
|
var url: string | null = null;
|
||||||
if (clickable_registries.includes(data.parts.registry)) {
|
if (clickable_registries.includes(data.parts.registry)) {
|
||||||
switch (data.parts.registry) {
|
switch (data.parts.registry) {
|
||||||
@@ -142,11 +155,36 @@ export default function Image({ data }: { data: Image }) {
|
|||||||
Checked in {data.time} ms
|
Checked in {data.time} ms
|
||||||
</div>
|
</div>
|
||||||
{data.result.error && (
|
{data.result.error && (
|
||||||
<div className="bg-yellow-400/10 flex items-center gap-3 overflow-hidden break-all rounded-md px-3 py-2">
|
<div className="bg-yellow-400/10 flex items-center gap-3 overflow-hidden break-all rounded-md px-3 py-2 mb-4">
|
||||||
<IconAlertTriangleFilled className="text-yellow-500 size-5 shrink-0" />
|
<IconAlertTriangleFilled className="text-yellow-500 size-5 shrink-0" />
|
||||||
{data.result.error}
|
{data.result.error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{data.result.has_update && (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
Pull command
|
||||||
|
<div
|
||||||
|
className={`bg-${theme}-50 dark:bg-${theme}-950 text-gray-500 flex items-center rounded-md px-3 py-2 font-mono mb-4 group relative`}
|
||||||
|
>
|
||||||
|
<p className="overflow-scroll">
|
||||||
|
docker pull {data.reference}
|
||||||
|
</p>
|
||||||
|
{navigator.clipboard &&
|
||||||
|
(copySuccess ? (
|
||||||
|
<IconCheck className="absolute right-3" />
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
className="absolute right-3 opacity-0 group-hover:opacity-100 transition-opacity duration-50"
|
||||||
|
onClick={handleCopy(
|
||||||
|
`docker pull ${data.reference}`
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<IconCopy />
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
Local digests
|
Local digests
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user