(props: {
readonly icon?: string;
readonly fallbackSrc?: string;
readonly className?: string;
readonly fallback?: React.ReactNode;
})
| 59 | * most in need of explaining itself. `fallback` is the last resort, for when |
| 60 | * there is no image of any kind. */ |
| 61 | export function PresetIcon(props: { |
| 62 | readonly icon?: string; |
| 63 | readonly fallbackSrc?: string; |
| 64 | readonly className?: string; |
| 65 | readonly fallback?: React.ReactNode; |
| 66 | }) { |
| 67 | const isExecutorIcon = props.icon?.startsWith(EXECUTOR_ICON_SCHEME) ?? false; |
| 68 | const [fetched, setFetched] = useState<string | null>(null); |
| 69 | |
| 70 | useEffect(() => { |
| 71 | if (!isExecutorIcon || props.icon === undefined) return; |
| 72 | let live = true; |
| 73 | void resolveExecutorIcon(props.icon.slice(EXECUTOR_ICON_SCHEME.length)).then((icon) => { |
| 74 | if (live) setFetched(icon); |
| 75 | }); |
| 76 | return () => { |
| 77 | live = false; |
| 78 | }; |
| 79 | }, [isExecutorIcon, props.icon]); |
| 80 | |
| 81 | const src = (isExecutorIcon ? fetched : (props.icon ?? null)) ?? props.fallbackSrc ?? null; |
| 82 | if (src === null) return <>{props.fallback ?? null}</>; |
| 83 | return <img src={src} alt="" className={props.className} loading="lazy" />; |
| 84 | } |
nothing calls this directly
no test coverage detected