diff --git a/app/components/Column.tsx b/app/components/Column.tsx index 5d476284..46d80e27 100644 --- a/app/components/Column.tsx +++ b/app/components/Column.tsx @@ -1,21 +1,36 @@ import { Title } from "./Primitives/Title"; import { colorForItemAtPath } from "~/utilities/colors"; -import { IconComponent } from "~/useColumnView"; +import { ColumnViewNode, IconComponent } from "~/useColumnView"; import { useJson } from "../hooks/useJson"; -import { memo, useMemo } from "react"; +import { memo, useCallback, useMemo, useRef } from "react"; +import { ColumnItem } from "./ColumnItem"; +import { useJsonColumnViewAPI } from "~/hooks/useJsonColumnView"; +import { useVirtual } from "react-virtual"; export type ColumnProps = { id: string; title: string; icon?: IconComponent; hasHighlightedElement: boolean; - children: React.ReactNode; + items: ColumnViewNode[]; + selectedPath: string[]; + highlightedPath: string[]; }; function ColumnElement(column: ColumnProps) { - const { id, title, children } = column; + const { id, title, items, selectedPath, highlightedPath } = column; const [json] = useJson(); const iconColor = useMemo(() => colorForItemAtPath(id, json), [id, json]); + const { goToNodeId } = useJsonColumnViewAPI(); + + const containerRef = useRef(null); + + const rowVirtualizer = useVirtual({ + size: items.length, + parentRef: containerRef, + estimateSize: useCallback(() => 36, []), + overscan: 5, + }); return (
} {title}
-
- {children} +
+
+ {rowVirtualizer.virtualItems.map((virtualRow) => { + const item = items[virtualRow.index]; + return ( +
+ goToNodeId(id, "columnView")} + /> +
+ ); + })} +
); diff --git a/app/components/Columns.tsx b/app/components/Columns.tsx index 823f3ebe..e3d118a7 100644 --- a/app/components/Columns.tsx +++ b/app/components/Columns.tsx @@ -14,7 +14,6 @@ function ColumnsElement({ columns }: { columns: ColumnDefinition[] }) { const [json] = useJson(); const { selectedPath, highlightedPath, highlightedNodeId } = useJsonColumnViewState(); - const { goToNodeId } = useJsonColumnViewAPI(); const highlightedItemIsValue = useMemo(() => { if (highlightedNodeId == null) { return false; @@ -38,20 +37,10 @@ function ColumnsElement({ columns }: { columns: ColumnDefinition[] }) { hasHighlightedElement={ highlightedPath[highlightedPath.length - 2] === column.id } - > - {column.items.map((item) => ( - goToNodeId(id, "columnView")} - /> - ))} - + selectedPath={selectedPath} + highlightedPath={highlightedPath} + items={column.items} + /> ); })} {highlightedItemIsValue ? : null}