Skip to content

Commit fcf775c

Browse files
committed
perf: lazy show action, reduce lcp time
Signed-off-by: Innei <tukon479@gmail.com>
1 parent 3fca96e commit fcf775c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

apps/renderer/src/modules/entry-column/Items/social-media-item.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ActionButton } from "@follow/components/ui/button/index.js"
22
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
33
import { cn } from "@follow/utils/utils"
44
import { atom } from "jotai"
5-
import { useLayoutEffect, useRef } from "react"
5+
import { useLayoutEffect, useRef, useState } from "react"
66

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

3535
const ref = useRef<HTMLDivElement>(null)
36-
36+
const [showAction, setShowAction] = useState(false)
3737
useLayoutEffect(() => {
3838
if (ref.current) {
3939
jotaiStore.set(socialMediaContentWidthAtom, ref.current.offsetWidth)
@@ -50,6 +50,8 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
5050

5151
return (
5252
<div
53+
onMouseEnter={() => setShowAction(true)}
54+
onMouseLeave={() => setShowAction(false)}
5355
className={cn(
5456
"relative flex px-8 py-6",
5557
"group",
@@ -157,14 +159,11 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
157159
)}
158160
</div>
159161

160-
<div
161-
className={cn(
162-
"absolute right-1 top-1.5",
163-
"invisible opacity-0 duration-200 group-hover:visible group-hover:opacity-80",
164-
)}
165-
>
166-
<ActionBar entryId={entryId} />
167-
</div>
162+
{showAction && (
163+
<div className={"absolute right-1 top-1.5"}>
164+
<ActionBar entryId={entryId} />
165+
</div>
166+
)}
168167
</div>
169168
)
170169
}

0 commit comments

Comments
 (0)