From 014a00386c3f389ffb5000a284f60e443e909353 Mon Sep 17 00:00:00 2001 From: plebbitor Date: Sat, 25 Mar 2023 21:38:52 +0100 Subject: [PATCH] improved performance from tooltips, slice --- src/components/views/Board.jsx | 51 +++++++++------------------------ src/components/views/Thread.jsx | 43 +++++++++++---------------- 2 files changed, 30 insertions(+), 64 deletions(-) diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index ca8bfc3f..c2cbdb01 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -44,10 +44,8 @@ const Board = () => { const navigate = useNavigate(); const [prevScrollPos, setPrevScrollPos] = useState(0); const [visible, setVisible] = useState(true); - const [endIndex, setEndIndex] = useState(5); const { feed, hasMore, loadMore } = useFeed({subplebbitAddresses: [`${selectedAddress}`], sortType: 'new'}); const [selectedFeed, setSelectedFeed] = useState(feed); - const renderedFeed = selectedFeed.slice(0, endIndex); const { subplebbitAddress } = useParams(); const handleClickForm = useClickForm(); @@ -80,17 +78,11 @@ const Board = () => { }, [prevScrollPos, visible]); - // reset endIndex whenever selectedAddress changes - useEffect(() => { - setEndIndex(5); - }, [selectedAddress]); const tryLoadMore = async () => { try { await loadMore(); - setSelectedFeed([...selectedFeed, ...feed]); - setEndIndex(endIndex + 2); } catch (e) { await new Promise(resolve => setTimeout(resolve, 1000)); } @@ -153,14 +145,6 @@ const Board = () => { }); }; - - - const handleScroll = (event) => { - const { scrollTop, scrollHeight, clientHeight } = event.currentTarget; - if (scrollTop + clientHeight >= scrollHeight) { - setEndIndex(endIndex + 5); - } - }; const handleVoidClick = () => {}; @@ -384,15 +368,16 @@ const Board = () => { + -
+
} > - {renderedFeed.map(thread => { + {feed.map(thread => { const { replies: { pages: { topAll: { comments } } } } = thread; const { renderedComments, omittedCount } = renderComments(comments); const commentMediaInfo = getCommentMediaInfo(thread); @@ -448,9 +433,8 @@ const Board = () => { {thread.title ? ( thread.title.length > 75 ? - {thread.title.slice(0, 75) + " (...)"} @@ -463,9 +447,8 @@ const Board = () => { {thread.author.displayName ? thread.author.displayName.length > 20 ? - {thread.author.displayName.slice(0, 20) + " (...)"} @@ -479,9 +462,8 @@ const Board = () => { (u/ {thread.author.address.length > 15 ? - {thread.author.address.slice(0, 15) + "..."} @@ -558,9 +540,8 @@ const Board = () => { {reply.author.displayName ? reply.author.displayName.length > 12 ? - {reply.author.displayName.slice(0, 12) + " (...)"} @@ -575,9 +556,8 @@ const Board = () => { (u/ {reply.author.address.length > 12 ? - {reply.author.address.slice(0, 12) + "..."} @@ -649,9 +629,8 @@ const Board = () => { {thread.author.displayName ? thread.author.displayName.length > 15 ? - {thread.author.displayName.slice(0, 15) + " (...)"} @@ -666,9 +645,8 @@ const Board = () => { (u/ {thread.author.address.length > 15 ? - {thread.author.address.slice(0, 15) + "..."} @@ -683,9 +661,8 @@ const Board = () => { {thread.title ? ( thread.title.length > 30 ? - {thread.title.slice(0, 30) + " (...)"} @@ -774,9 +751,8 @@ const Board = () => { {reply.author.displayName ? reply.author.displayName.length > 12 ? - {reply.author.displayName.slice(0, 12) + " (...)"} @@ -791,9 +767,8 @@ const Board = () => { (u/ {reply.author.address.length > 10 ? - {reply.author.address.slice(0, 10) + "..."} diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index ed8a6eb4..94383837 100644 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, Suspense} from 'react'; import { Link, useNavigate, useParams } from 'react-router-dom'; import { Tooltip } from 'react-tooltip'; import { useComment, usePublishComment } from '@plebbit/plebbit-react-hooks'; @@ -393,6 +393,7 @@ const Thread = () => { )}
+ {comment !== undefined ? ( <> @@ -436,9 +437,8 @@ const Thread = () => { {comment.title ? ( comment.title.length > 75 ? <> - {comment.title.slice(0, 75) + " (...)"} @@ -452,9 +452,8 @@ const Thread = () => { {comment.author?.displayName ? comment.author?.displayName.length > 20 ? <> - {comment.author?.displayName.slice(0, 20) + " (...)"} @@ -470,9 +469,8 @@ const Thread = () => { (u/ {comment.author?.address.length > 20 ? <> - {comment.author?.address.slice(0, 20) + "..."} @@ -517,7 +515,7 @@ const Thread = () => { const renderedComments = renderThreadComments(comment.replies.pages.topAll.comments); return renderedComments.map(reply => { return ( -
+
{'>>'}
@@ -526,9 +524,8 @@ const Thread = () => { {reply.author.displayName ? reply.author.displayName.length > 20 ? <> - {reply.author.displayName.slice(0, 20) + " (...)"} @@ -543,9 +540,8 @@ const Thread = () => { (u/ {reply.author.address.length > 20 ? <> - {reply.author.address.slice(0, 20) + "..."} @@ -592,9 +588,9 @@ const Thread = () => { }) })}
-
+

-
+
@@ -602,9 +598,8 @@ const Thread = () => { {comment.author?.displayName ? comment.author?.displayName.length > 15 ? <> - {comment.author?.displayName.slice(0, 15) + " (...)"} @@ -619,9 +614,8 @@ const Thread = () => { (u/ {comment.author?.address.length > 15 ? <> - {comment.author?.address.slice(0, 15) + "..."} @@ -636,9 +630,8 @@ const Thread = () => { {comment.title ? ( comment.title.length > 30 ? <> - {comment.title.slice(0, 30) + " (...)"} @@ -701,7 +694,7 @@ const Thread = () => { const renderedComments = renderThreadComments(comment.replies.pages.topAll.comments); return renderedComments.map(reply => { return ( -
+
@@ -709,9 +702,8 @@ const Thread = () => { {reply.author.displayName ? reply.author.displayName.length > 12 ? <> - {reply.author.displayName.slice(0, 12) + " (...)"} @@ -726,9 +718,8 @@ const Thread = () => { (u/ {reply.author.address.length > 12 ? <> - {reply.author.address.slice(0, 12) + "..."} @@ -851,7 +842,7 @@ const Thread = () => {
- ) : ( + ) : ( )}