Show local image previews while uploads run in background
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
"use client";
|
||||
import { createContext, useContext } from "react";
|
||||
export const ImagePreviews = createContext<{ sources: Map<string,string>; loaded: (id: string) => void }>({ sources: new Map(), loaded: () => {} });
|
||||
export function CanvasImage({ id, src, title, className }: { id: string; src?: string; title: string; className: string }) {
|
||||
const previews = useContext(ImagePreviews), local = previews.sources.get(id);
|
||||
const remote = <img loading="lazy" decoding="async" className={className} src={src} alt={title} draggable={false} referrerPolicy="no-referrer" onLoad={() => previews.loaded(id)} />;
|
||||
if (!local || local === src) return remote;
|
||||
return <div style={{position:"relative",width:"100%",height:"100%",minHeight:0,flex:1,borderRadius:"inherit"}}>{remote}<img className={className} src={local} alt="" aria-hidden draggable={false} style={{position:"absolute",inset:0,pointerEvents:"none"}} /></div>;
|
||||
}
|
||||
Reference in New Issue
Block a user