From 2ed81c857c999606aad4b3d26d764673725acc1d Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 14 Nov 2024 16:50:37 +0100 Subject: [PATCH] refactor(comments): reduce initial load wait and add discovered --- src/components/comment/index.tsx | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/components/comment/index.tsx b/src/components/comment/index.tsx index 6e1a030..b9a87b3 100644 --- a/src/components/comment/index.tsx +++ b/src/components/comment/index.tsx @@ -62,8 +62,8 @@ export const Comments = ({ addressable, setCommentCount }: Props) => { const [isLoading, setIsLoading] = useState(true) useEffect(() => { - // Initial loading to indicate comments fetching (stop after 15 seconds) - const t = window.setTimeout(() => setIsLoading(false), 15000) + // Initial loading to indicate comments fetching (stop after 5 seconds) + const t = window.setTimeout(() => setIsLoading(false), 5000) return () => { window.clearTimeout(t) } @@ -185,8 +185,18 @@ export const Comments = ({ addressable, setCommentCount }: Props) => { return true } + const handleDiscoveredClick = () => { + setVisible(commentEvents) + } + const [visible, setVisible] = useState([]) + useEffect(() => { + if (isLoading) { + setVisible(commentEvents) + } + }, [commentEvents, isLoading]) + const comments = useMemo(() => { - let filteredComments = commentEvents + let filteredComments = visible if (filterOptions.author === AuthorFilterEnum.Creator_Comments) { filteredComments = filteredComments.filter( (comment) => comment.pubkey === addressable.author @@ -200,14 +210,28 @@ export const Comments = ({ addressable, setCommentCount }: Props) => { } return filteredComments - }, [commentEvents, filterOptions, addressable.author]) + }, [visible, filterOptions.author, filterOptions.sort, addressable.author]) + const discoveredCount = commentEvents.length - visible.length return (

Comments

{/* Hide comment form if aTag is missing */} {!!addressable.aTag && } +
+ {isLoading ? ( + + ) : ( + + )} +
{ ))}
- {isLoading && }
)