resolver rework

This commit is contained in:
2024-08-21 15:19:41 -06:00
parent 3417fdd3d7
commit 9c9edd9e90
2 changed files with 144 additions and 79 deletions

View File

@@ -8,7 +8,15 @@ export function Resolver({ resolver }: { resolver: string }) {
const [res] = useState(new TTCQueryResolver(parser));
const [content, setContent] = useState<ReactNode>("");
useEffect(() => {
setContent(res.resolve(resolver));
let resolved = res.resolve(resolver);
setContent(
typeof resolved?.display === "function" ? (
<resolved.display />
) : (
resolved?.display
)
);
}, [resolver, res]);
return <span>{content}</span>;
}
@@ -31,8 +39,9 @@ export function OnDemandResolver({
for (const idx of stackIdxs) {
let thing = res.current.getFromStack(idx);
if (Array.isArray(thing)) thing = thing.at(0);
if (typeof thing === "function") thing = thing();
content = content.replaceAll(idx, thing as string);
if (typeof thing.display === "function")
content = content.replaceAll(idx, thing.display() as string);
else content = content.replaceAll(idx, thing.display as string);
}
setContent(content);
}, [res, template]);