MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / PresetIcon

Function PresetIcon

packages/react/src/components/preset-icon.tsx:61–84  ·  view source on GitHub ↗
(props: {
  readonly icon?: string;
  readonly fallbackSrc?: string;
  readonly className?: string;
  readonly fallback?: React.ReactNode;
})

Source from the content-addressed store, hash-verified

59 * most in need of explaining itself. `fallback` is the last resort, for when
60 * there is no image of any kind. */
61export 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}

Callers

nothing calls this directly

Calls 1

resolveExecutorIconFunction · 0.85

Tested by

no test coverage detected