Skip to content

Commit

Permalink
perf: lazy show action, reduce lcp time
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Nov 19, 2024
1 parent 3fca96e commit fcf775c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions apps/renderer/src/modules/entry-column/Items/social-media-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionButton } from "@follow/components/ui/button/index.js"
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
import { cn } from "@follow/utils/utils"
import { atom } from "jotai"
import { useLayoutEffect, useRef } from "react"
import { useLayoutEffect, useRef, useState } from "react"

import { RelativeTime } from "~/components/ui/datetime"
import { Media } from "~/components/ui/media"
Expand Down Expand Up @@ -33,7 +33,7 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
const feed = useFeedById(entry?.feedId)

const ref = useRef<HTMLDivElement>(null)

const [showAction, setShowAction] = useState(false)
useLayoutEffect(() => {
if (ref.current) {
jotaiStore.set(socialMediaContentWidthAtom, ref.current.offsetWidth)
Expand All @@ -50,6 +50,8 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl

return (
<div
onMouseEnter={() => setShowAction(true)}
onMouseLeave={() => setShowAction(false)}
className={cn(
"relative flex px-8 py-6",
"group",
Expand Down Expand Up @@ -157,14 +159,11 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
)}
</div>

<div
className={cn(
"absolute right-1 top-1.5",
"invisible opacity-0 duration-200 group-hover:visible group-hover:opacity-80",
)}
>
<ActionBar entryId={entryId} />
</div>
{showAction && (
<div className={"absolute right-1 top-1.5"}>
<ActionBar entryId={entryId} />
</div>
)}
</div>
)
}
Expand Down

0 comments on commit fcf775c

Please sign in to comment.