///
import { useState } from "react";
import { Clipboard, Download, FileText, Menu } from "lucide-react";
import { hydrateIsland } from "@/client/hydrate";
import { Button, buttonClasses } from "@/client/components/ui/button";
export type BlobActionsProps = {
viewRawHref: string;
rawHref: string;
showCopy: boolean;
isImage?: boolean;
isPdf?: boolean;
};
export function BlobActionsIsland({
viewRawHref,
rawHref,
showCopy,
isImage,
isPdf,
}: BlobActionsProps) {
const [copyLabel, setCopyLabel] = useState("Copy");
async function copyRawText() {
try {
const response = await fetch(viewRawHref);
const text = await response.text();
await navigator.clipboard.writeText(text);
setCopyLabel("Copied");
window.setTimeout(() => setCopyLabel("Copy"), 1200);
} catch (error) {
console.warn("Copy failed", error);
}
}
return (
{showCopy ? (
) : null}
{!isImage && !isPdf ? (
View
) : null}
Raw
{showCopy ? (
) : null}
{!isImage && !isPdf ? (
View raw
) : null}
Download
);
}
export function initBlobActions() {
hydrateIsland("blob-actions", BlobActionsIsland);
}