import { CheckCircleIcon, DownloadIcon } from "@lume/icons"; import { downloadDir } from "@tauri-apps/api/path"; import { WebviewWindow } from "@tauri-apps/api/webviewWindow"; import { download } from "@tauri-apps/plugin-upload"; import { type SyntheticEvent, useState } from "react"; export function ImagePreview({ url }: { url: string }) { const [downloaded, setDownloaded] = useState(false); const downloadImage = async (e: { stopPropagation: () => void }) => { try { e.stopPropagation(); const downloadDirPath = await downloadDir(); const filename = url.substring(url.lastIndexOf("/") + 1); await download(url, `${downloadDirPath}/${filename}`); setDownloaded(true); } catch (e) { console.error(e); } }; const open = async () => { const name = new URL(url).pathname.split("/").pop(); return new WebviewWindow("image-viewer", { url, title: name, }); }; const fallback = (event: SyntheticEvent) => { event.currentTarget.src = "/fallback-image.jpg"; }; return ( // biome-ignore lint/a11y/useKeyWithClickEvents:
open()} className="group relative my-1"> {url}
); }