import { WebviewWindow } from "@tauri-apps/api/webviewWindow"; export function ImagePreview({ url }: { url: string }) { const open = async (url: string) => { const name = new URL(url).pathname .split("/") .pop() .replace(/[^a-zA-Z ]/g, ""); const label = `viewer-${name}`; const window = WebviewWindow.getByLabel(label); if (!window) { const newWindow = new WebviewWindow(label, { url, title: "Image Viewer", width: 800, height: 800, titleBarStyle: "overlay", }); return newWindow; } return await window.setFocus(); }; return (
{url} open(url)} onKeyDown={() => open(url)} onError={({ currentTarget }) => { currentTarget.onerror = null; currentTarget.src = "/404.jpg"; }} />
); }