From fd29975cf9e939ed426f7965ce0d820ef27b6abf Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 18 Apr 2025 23:14:36 +0800 Subject: [PATCH] fix(entry-column): remove entry item should calculate layout - Introduced EntryVirtualListItem to enhance the rendering of entries in a virtualized list. - Updated EntryList to utilize EntryVirtualListItem, improving performance and structure. - Removed redundant keydown handling logic from EntryList, streamlining the component. Signed-off-by: Innei --- .../src/modules/entry-column/item.tsx | 17 +++++++++- .../src/modules/entry-column/list.tsx | 32 ++++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/apps/desktop/src/renderer/src/modules/entry-column/item.tsx b/apps/desktop/src/renderer/src/modules/entry-column/item.tsx index 5a26c70f1..80ce3144b 100644 --- a/apps/desktop/src/renderer/src/modules/entry-column/item.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-column/item.tsx @@ -3,7 +3,7 @@ import type { FeedViewType } from "@follow/constants" import { views } from "@follow/constants" import { cn } from "@follow/utils/utils" import type { FC } from "react" -import { memo } from "react" +import { forwardRef, memo } from "react" import { useEntryTranslation } from "~/store/ai/hook" import type { FlatEntryModel } from "~/store/entry" @@ -37,6 +37,21 @@ export const EntryItem: FC = memo(({ entryId, view }) => { return }) +export const EntryVirtualListItem = forwardRef< + HTMLDivElement, + EntryItemProps & React.DetailedHTMLProps, HTMLDivElement> +>(({ entryId, view, className, ...props }, ref) => { + const entry = useEntry(entryId) + + if (!entry) return
+ + return ( +
+ +
+ ) +}) + const LoadingCircleFallback = (
diff --git a/apps/desktop/src/renderer/src/modules/entry-column/list.tsx b/apps/desktop/src/renderer/src/modules/entry-column/list.tsx index 46e172e20..253944222 100644 --- a/apps/desktop/src/renderer/src/modules/entry-column/list.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-column/list.tsx @@ -13,7 +13,6 @@ import { Fragment, memo, startTransition, - useCallback, useEffect, useMemo, useRef, @@ -30,11 +29,7 @@ import { isListSubscription } from "~/store/subscription" import { DateItem } from "./components/DateItem" import { EntryColumnShortcutHandler } from "./EntryColumnShortcutHandler" -import { EntryItem, EntryItemSkeleton } from "./item" - -export const EntryListContent = forwardRef((props, ref) => ( -
-)) +import { EntryItemSkeleton, EntryVirtualListItem } from "./item" export const EntryEmptyList = forwardRef>((props, ref) => { const unreadOnly = useGeneralSettingKey("unreadOnly") @@ -82,6 +77,12 @@ export type EntryListProps = { const capacity = 3 const offsetCache = new LRUCache(capacity) const measurementsCache = new LRUCache(capacity) +// Prevent scroll list move when press up/down key, the up/down key should be taken over by the shortcut key we defined. +const handleKeyDown: React.KeyboardEventHandler = (e) => { + if (e.key === "ArrowDown" || e.key === "ArrowUp") { + e.preventDefault() + } +} export const EntryList: FC = memo( ({ feedId, @@ -96,13 +97,6 @@ export const EntryList: FC = memo( onRangeChange, gap, }) => { - // Prevent scroll list move when press up/down key, the up/down key should be taken over by the shortcut key we defined. - const handleKeyDown: React.KeyboardEventHandler = useCallback((e) => { - if (e.key === "ArrowDown" || e.key === "ArrowUp") { - e.preventDefault() - } - }, []) - const scrollRef = useScrollViewElement() const stickyIndexes = useMemo( @@ -268,17 +262,17 @@ export const EntryList: FC = memo( />
)} -
- -
+ /> ) })}