Cache restoreScrollPos to avoid render

`CommentCreate` was getting marked for every comment that comes in because the parent was marked.
This commit is contained in:
infinite-persistence 2021-10-08 14:33:31 +08:00
parent 4b0318cd38
commit 5d8fc40051
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -63,11 +63,11 @@ export default function LivestreamComments(props: Props) {
const pinnedComment = pinnedComments.length > 0 ? pinnedComments[0] : null; const pinnedComment = pinnedComments.length > 0 ? pinnedComments[0] : null;
function restoreScrollPos() { const restoreScrollPos = React.useCallback(() => {
if (discussionElement) { if (discussionElement) {
discussionElement.scrollTop = 0; discussionElement.scrollTop = 0;
} }
} }, [discussionElement]);
React.useEffect(() => { React.useEffect(() => {
if (claimId) { if (claimId) {
@ -139,10 +139,10 @@ export default function LivestreamComments(props: Props) {
const clonedSuperchats = JSON.parse(JSON.stringify(superChatsByTipAmount)); const clonedSuperchats = JSON.parse(JSON.stringify(superChatsByTipAmount));
// for top to bottom display, oldest superchat on top most recent on bottom // for top to bottom display, oldest superchat on top most recent on bottom
superChatsReversed = clonedSuperchats superChatsReversed = clonedSuperchats.sort((a, b) => {
.sort((a, b) => {
return b.timestamp - a.timestamp; return b.timestamp - a.timestamp;
}); } });
}
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine // todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
function isMyComment(channelId: string) { function isMyComment(channelId: string) {