Skip to content

Commit

Permalink
refactor: optimize data fetching in BlockDisplay component
Browse files Browse the repository at this point in the history
  • Loading branch information
hngngn committed Jan 1, 2025
1 parent e3283b8 commit 75a072a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions docs/src/components/block-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ import {
import type { RegistryEntry } from "@/registry/schema";
import { createAsync } from "@solidjs/router";
import { clientOnly } from "@solidjs/start";
import { Show, createMemo } from "solid-js";
import { Show } from "solid-js";

const BlockViewer = clientOnly(() => import("./block-viewer"), { lazy: true });

const BlockDisplay = (props: { name: string }) => {
const item = createMemo<RegistryEntry>(() => Index.tailwindcss[props.name]);
const tree = createAsync(() => getCachedFileTree(item().files));
const highlightedFiles = createAsync(() =>
getCachedHighlightedFiles(item().files),
);
const block = createAsync<RegistryEntry>(() => Index.tailwindcss[props.name]);
const data = createAsync(async () => {
const [tree, highlightedFiles] = await Promise.all([
getCachedFileTree(block()?.files),
getCachedHighlightedFiles(block()?.files),
]);

return { tree, highlightedFiles };
});

return (
<Show when={item().files && tree() && highlightedFiles()}>
<Show when={block()?.files && data()?.tree && data()?.highlightedFiles}>
<BlockViewer
item={item()}
tree={tree()!}
highlightedFiles={highlightedFiles()!}
item={block()}
tree={data()!.tree}
highlightedFiles={data()!.highlightedFiles}
/>
</Show>
);
Expand Down

0 comments on commit 75a072a

Please sign in to comment.