perf: resolve feed item select area performance problem (#1176)

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2024-10-27 18:19:41 +08:00
committed by GitHub
parent 30e2f815de
commit e1816e1a12
3 changed files with 14 additions and 5 deletions
@@ -1,5 +1,6 @@
import { ActionButton } from "@follow/components/ui/button/index.js"
import { Routes, views } from "@follow/constants"
import { useTypeScriptHappyCallback } from "@follow/hooks"
import { useSubscribeElectronEvent } from "@follow/shared/event"
import { stopPropagation } from "@follow/utils/dom"
import { clamp, cn } from "@follow/utils/utils"
@@ -24,6 +25,7 @@ import { useSubscriptionStore } from "~/store/subscription"
import { useFeedUnreadStore } from "~/store/unread"
import { WindowUnderBlur } from "../../components/ui/background"
import { getSelectedFeedIds, setSelectedFeedIds } from "./atom"
import { FeedColumnHeader } from "./header"
import { FeedList } from "./list"
@@ -190,7 +192,16 @@ export function FeedColumn({ children, className }: PropsWithChildren<{ classNam
</ActionButton>
))}
</div>
<div className="relative flex size-full overflow-hidden" ref={carouselRef}>
<div
className="relative flex size-full overflow-hidden"
ref={carouselRef}
onPointerDown={useTypeScriptHappyCallback((e) => {
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
const nextSelectedFeedIds = getSelectedFeedIds()
setSelectedFeedIds(nextSelectedFeedIds.length === 0 ? nextSelectedFeedIds : [])
}
}, [])}
>
<SwipeWrapper active={active}>
{views.map((item, index) => (
<section key={item.name} className="h-full w-feed-col shrink-0 snap-center">
@@ -80,11 +80,8 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
})
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown((e) => {
useAnyPointDown(() => {
setIsContextMenuOpen(false)
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
setSelectedFeedIds([])
}
})
if (!feed) return null
@@ -189,6 +189,7 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
hitRate={10}
onSelect={(e) => {
const allChanged = [...e.added, ...e.removed]
setSelectedFeedIds((prev) => {
const added = allChanged
.map((el) => el.dataset.feedId)