feat: reduce the rendering jitter of the post sidebar
This commit is contained in:
@@ -60,7 +60,7 @@ export const ReactionComment: React.FC<{
|
||||
)
|
||||
})()}
|
||||
<span className={cn("leading-snug")}>
|
||||
{comments.data?.pages?.[0]?.count}
|
||||
{!comments.isLoading ? comments.data?.pages?.[0]?.count : "-"}
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -41,7 +41,7 @@ export const ReactionLike: React.FC<{
|
||||
characterId,
|
||||
noteId,
|
||||
})
|
||||
const { data: likeCount = 0 } = useGetLikeCounts({
|
||||
const likeCounts = useGetLikeCounts({
|
||||
characterId,
|
||||
noteId,
|
||||
})
|
||||
@@ -150,12 +150,14 @@ export const ReactionLike: React.FC<{
|
||||
inner
|
||||
)
|
||||
})()}
|
||||
<span className="leading-snug">{likeCount}</span>
|
||||
<span className="leading-snug">
|
||||
{!likeCounts.isLoading ? likeCounts.data : "-"}
|
||||
</span>
|
||||
</Button>
|
||||
{showAvatarStack && (
|
||||
<AvatarStack
|
||||
avatars={avatars}
|
||||
count={likeCount}
|
||||
count={likeCounts.data || 0}
|
||||
onClick={() => setIsLikeListOpen(true)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -142,7 +142,7 @@ export const ReactionMint: React.FC<{
|
||||
)
|
||||
})()}
|
||||
<span className={cn("leading-snug", vertical ? "" : "ml-2")}>
|
||||
{mints.data?.pages?.[0]?.count || 0}
|
||||
{!mints.isLoading ? mints.data?.pages?.[0]?.count || 0 : "-"}
|
||||
</span>
|
||||
</Button>
|
||||
{showAvatarStack && (
|
||||
|
||||
@@ -94,7 +94,7 @@ export const ReactionTip: React.FC<{
|
||||
)
|
||||
})()}
|
||||
<span className={cn("leading-snug", vertical ? "" : "ml-2")}>
|
||||
{tips.data?.pages?.[0]?.count || 0}
|
||||
{!tips.isLoading ? tips.data?.pages?.[0]?.count || 0 : "-"}
|
||||
</span>
|
||||
</Button>
|
||||
{showAvatarStack && (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import React, { useEffect, useRef, useState } from "react"
|
||||
import React, { useRef } from "react"
|
||||
|
||||
import { ReactionComment } from "~/components/common/ReactionComment"
|
||||
import { ReactionLike } from "~/components/common/ReactionLike"
|
||||
@@ -16,24 +16,12 @@ export const PostActions: React.FC<{
|
||||
}> = ({ page, site }) => {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
const [maxWidth, setMaxWidth] = useState(0)
|
||||
useEffect(() => {
|
||||
if (containerRef?.current) {
|
||||
setMaxWidth(
|
||||
(window.innerWidth -
|
||||
(containerRef.current?.parentElement?.clientWidth || 0)) /
|
||||
2 -
|
||||
40,
|
||||
)
|
||||
}
|
||||
}, [containerRef])
|
||||
const isPostFooterInView = usePostFooterInView()
|
||||
|
||||
return (
|
||||
<div
|
||||
className="xlog-post-actions absolute right-full pr-14 h-full top-0 transition-all duration-1000"
|
||||
className="xlog-post-actions absolute right-full pr-14 h-full top-0 transition-[visibility,opacity] lg:block hidden"
|
||||
style={{
|
||||
display: maxWidth > 60 ? "block" : "none",
|
||||
opacity: isPostFooterInView ? 0 : 1,
|
||||
visibility: isPostFooterInView ? "hidden" : "visible",
|
||||
}}
|
||||
|
||||
@@ -135,28 +135,12 @@ export const PostToc: React.FC<{
|
||||
}> = ({ data }) => {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
const [maxWidth, setMaxWidth] = useState(0)
|
||||
useEffect(() => {
|
||||
if (containerRef?.current) {
|
||||
setMaxWidth(
|
||||
(window.innerWidth -
|
||||
(containerRef.current?.parentElement?.clientWidth || 0)) /
|
||||
2 -
|
||||
40,
|
||||
)
|
||||
}
|
||||
}, [containerRef])
|
||||
|
||||
const idList = getIds(data?.map)
|
||||
const activeId = useActiveId(idList)
|
||||
|
||||
return (
|
||||
<div
|
||||
className="xlog-post-toc absolute left-full pl-10 h-full top-0"
|
||||
style={{
|
||||
maxWidth: maxWidth > 60 ? maxWidth : 0,
|
||||
display: maxWidth > 60 ? "block" : "none",
|
||||
}}
|
||||
className="xlog-post-toc absolute left-full pl-10 h-full top-0 lg:block hidden"
|
||||
ref={containerRef}
|
||||
>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user