From ed4da52f2ea4649262f3807a5e6cb982c153651f Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 7 Jun 2023 20:00:07 +0100 Subject: [PATCH] feat: reduce the rendering jitter of the post sidebar --- src/components/common/ReactionComment.tsx | 2 +- src/components/common/ReactionLike.tsx | 8 +++++--- src/components/common/ReactionMint.tsx | 2 +- src/components/common/ReactionTip.tsx | 2 +- src/components/site/PostActions.tsx | 16 ++-------------- src/components/site/PostToc.tsx | 18 +----------------- 6 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/components/common/ReactionComment.tsx b/src/components/common/ReactionComment.tsx index 634257ee..30463570 100644 --- a/src/components/common/ReactionComment.tsx +++ b/src/components/common/ReactionComment.tsx @@ -60,7 +60,7 @@ export const ReactionComment: React.FC<{ ) })()} - {comments.data?.pages?.[0]?.count} + {!comments.isLoading ? comments.data?.pages?.[0]?.count : "-"} diff --git a/src/components/common/ReactionLike.tsx b/src/components/common/ReactionLike.tsx index b90d4c98..d69b6c13 100644 --- a/src/components/common/ReactionLike.tsx +++ b/src/components/common/ReactionLike.tsx @@ -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 ) })()} - {likeCount} + + {!likeCounts.isLoading ? likeCounts.data : "-"} + {showAvatarStack && ( setIsLikeListOpen(true)} /> )} diff --git a/src/components/common/ReactionMint.tsx b/src/components/common/ReactionMint.tsx index 22e4dea6..c5cfa959 100644 --- a/src/components/common/ReactionMint.tsx +++ b/src/components/common/ReactionMint.tsx @@ -142,7 +142,7 @@ export const ReactionMint: React.FC<{ ) })()} - {mints.data?.pages?.[0]?.count || 0} + {!mints.isLoading ? mints.data?.pages?.[0]?.count || 0 : "-"} {showAvatarStack && ( diff --git a/src/components/common/ReactionTip.tsx b/src/components/common/ReactionTip.tsx index fe32c998..71298fd2 100644 --- a/src/components/common/ReactionTip.tsx +++ b/src/components/common/ReactionTip.tsx @@ -94,7 +94,7 @@ export const ReactionTip: React.FC<{ ) })()} - {tips.data?.pages?.[0]?.count || 0} + {!tips.isLoading ? tips.data?.pages?.[0]?.count || 0 : "-"} {showAvatarStack && ( diff --git a/src/components/site/PostActions.tsx b/src/components/site/PostActions.tsx index 98f42040..7cfa03ef 100644 --- a/src/components/site/PostActions.tsx +++ b/src/components/site/PostActions.tsx @@ -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(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 (
60 ? "block" : "none", opacity: isPostFooterInView ? 0 : 1, visibility: isPostFooterInView ? "hidden" : "visible", }} diff --git a/src/components/site/PostToc.tsx b/src/components/site/PostToc.tsx index a2d36d20..008350cb 100644 --- a/src/components/site/PostToc.tsx +++ b/src/components/site/PostToc.tsx @@ -135,28 +135,12 @@ export const PostToc: React.FC<{ }> = ({ data }) => { const containerRef = useRef(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 (
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} >