diff --git a/front/packages/ui/src/fetch-infinite.web.tsx b/front/packages/ui/src/fetch-infinite.web.tsx index 103a5ae0..48c8d28d 100644 --- a/front/packages/ui/src/fetch-infinite.web.tsx +++ b/front/packages/ui/src/fetch-infinite.web.tsx @@ -32,6 +32,7 @@ import { } from "react"; import { Stylable, nativeStyleToCss, useYoshiki, ysMap } from "yoshiki"; import { EmptyView, ErrorView, Layout, WithLoading, addHeader } from "./fetch"; +import { Grid } from "./grid.web"; import type { ContentStyle } from "@shopify/flash-list"; import { useVirtualizer } from "@tanstack/react-virtual"; @@ -60,6 +61,12 @@ const InfiniteScroll = ({ contentContainerStyle?: ContentStyle; getItemSize: (x: T, idx: number) => number; } & Stylable) => { + return ( + layout.size as any} data={data} layout={layout}> + {renderItem} + + ); + const ref = useRef(null); const containerRef = useRef(null); const virtualizer = useVirtualizer({ diff --git a/front/packages/ui/src/fetch.tsx b/front/packages/ui/src/fetch.tsx index a30fe726..0730b24b 100644 --- a/front/packages/ui/src/fetch.tsx +++ b/front/packages/ui/src/fetch.tsx @@ -27,7 +27,7 @@ import { useYoshiki } from "yoshiki/native"; export type Layout = { numColumns: Breakpoint; - size: number; + padding: number; gap: Breakpoint; layout: "grid" | "horizontal" | "vertical"; }; diff --git a/front/packages/ui/src/grid.web.tsx b/front/packages/ui/src/grid.web.tsx new file mode 100644 index 00000000..faec4de8 --- /dev/null +++ b/front/packages/ui/src/grid.web.tsx @@ -0,0 +1,78 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +import { ReactNode, useRef } from "react"; +import { Layout } from "./fetch"; +import { useVirtualizer } from "@tanstack/react-virtual"; + +export const Grid = ({ + data, + children, + layout, + getItemSize, + ...props +}: { + data: T[]; + children: (item: T, index: number) => ReactNode; + layout: Layout; + getItemSize: (item: T, index: number) => number; +}) => { + const ref = useRef(null); + const virtualizer = useVirtualizer({ + // horizontal: layout.layout === "horizontal", + count: data.length, + getScrollElement: () => ref.current, + estimateSize: (i) => 350, //getItemSize(data[i], i), + overscan: 5, + }); + console.log(virtualizer); + console.log(virtualizer.getTotalSize()); + + return ( +
+
+ {virtualizer.getVirtualItems().map((x) => ( +
+ {children(data[x.index], x.index)} +
+ ))} +
+
+ ); +};