From 4e26a266a7eac9475f9944d35eef39b3dbefb60f Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 1 Jun 2024 13:52:43 +0800 Subject: [PATCH] feat: VirtuosoGrid for grid mode view --- .../src/components/entry-column/index.tsx | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/renderer/src/components/entry-column/index.tsx b/src/renderer/src/components/entry-column/index.tsx index b126be1fb..48b54e234 100644 --- a/src/renderer/src/components/entry-column/index.tsx +++ b/src/renderer/src/components/entry-column/index.tsx @@ -1,7 +1,6 @@ import { Tabs, TabsList, TabsTrigger } from "@renderer/components/ui/tabs" import { gridMode } from "@renderer/lib/constants" import { buildStorageNS } from "@renderer/lib/ns" -import { cn } from "@renderer/lib/utils" import { apiClient } from "@renderer/queries/api-fetch" import { useEntries } from "@renderer/queries/entries" import { useFeedStore } from "@renderer/store" @@ -13,7 +12,7 @@ import { debounce } from "lodash-es" import type { FC } from "react" import { forwardRef } from "react" import type { ListRange } from "react-virtuoso" -import { Virtuoso } from "react-virtuoso" +import { Virtuoso, VirtuosoGrid } from "react-virtuoso" import { useEventCallback } from "usehooks-ts" import { useShallow } from "zustand/react/shallow" @@ -96,34 +95,45 @@ export function EntryColumn() { ), ) + const virtusoOptions = { + components: { + List: ListContent, + }, + overscan: window.innerHeight, + rangeChanged: handleRangeChange, + totalCount: entries.data?.pages?.[0]?.total, + endReached: () => entries.hasNextPage && entries.fetchNextPage(), + data: entries.data?.pages.flatMap((page) => page.data) || [], + itemContent: (_, entry) => { + if (!entry) return null + return ( + + + + ) + }, + } + return (
- {/* TODO VirtuosoGrid */} - entries.hasNextPage && entries.fetchNextPage()} - data={entries.data?.pages.flatMap((page) => page.data)} - itemContent={(_, entry) => { - if (!entry) return null - return ( - - - - ) - }} - /> + {activeList?.view && gridMode.has(activeList.view) ? + ( + + ) : + ( + + )}
) } @@ -179,12 +189,7 @@ const ListContent = forwardRef((props, ref) => { initial={{ opacity: 0.01, y: 100 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0.01, y: -100 }} - className={cn( - "px-2", - activeList?.view && - gridMode.has(activeList.view) && - "grid grid-cols-2 gap-2 md:grid-cols-3 lg:grid-cols-4", - )} + className="px-2" {...props} ref={ref} />