Skip to content

Commit

Permalink
refactor: rename sticky check functions for clarity (#2542)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs authored Jan 11, 2025
1 parent d77ed3c commit 0a64473
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions apps/renderer/src/modules/entry-column/list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmptyIcon } from "@follow/components/icons/empty.jsx"
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
import { FeedViewType } from "@follow/constants"
import type { FeedViewType } from "@follow/constants"
import { useTypeScriptHappyCallback } from "@follow/hooks"
import { LRUCache } from "@follow/utils/lru-cache"
import type { Range, VirtualItem, Virtualizer } from "@tanstack/react-virtual"
Expand Down Expand Up @@ -161,8 +161,8 @@ export const EntryList: FC<EntryListProps> = memo(
})

const activeStickyIndexRef = useRef(0)
const isActiveSticky = (index: number) => activeStickyIndexRef.current === index
const isSticky = (index: number) => stickyIndexes.includes(index)
const checkIsActiveSticky = (index: number) => activeStickyIndexRef.current === index
const checkIsStickyItem = (index: number) => stickyIndexes.includes(index)

const virtualItems = rowVirtualizer.getVirtualItems()
useEffect(() => {
Expand Down Expand Up @@ -242,20 +242,20 @@ export const EntryList: FC<EntryListProps> = memo(
</div>
)
}
const activeSticky = isActiveSticky(virtualRow.index)
const sticky = isSticky(virtualRow.index)
const isStickyItem = checkIsStickyItem(virtualRow.index)
const isActiveStickyItem = !isScrollTop && checkIsActiveSticky(virtualRow.index)
return (
<Fragment key={virtualRow.key}>
{sticky && (
{isStickyItem && (
<div
className={clsx(
"bg-background",
activeSticky
isActiveStickyItem
? "sticky top-0 z-[1]"
: "absolute left-0 top-0 z-[2] w-full will-change-transform",
: "absolute left-0 top-0 w-full will-change-transform",
)}
style={
!activeSticky
!isActiveStickyItem
? {
transform,
}
Expand All @@ -264,19 +264,15 @@ export const EntryList: FC<EntryListProps> = memo(
>
<EntryHeadDateItem
entryId={entriesIds[virtualRow.index]}
isSticky={!isScrollTop && activeSticky}
isSticky={isActiveStickyItem}
/>
</div>
)}
<div
className="absolute left-0 top-0 w-full will-change-transform"
style={{
transform,
paddingTop: sticky
? view === FeedViewType.SocialMedia
? "3.5rem"
: "1.5rem"
: undefined,
paddingTop: isStickyItem ? "1.75rem" : undefined,
}}
ref={rowVirtualizer.measureElement}
data-index={virtualRow.index}
Expand Down

0 comments on commit 0a64473

Please sign in to comment.