From 49e3ec5e93c9f314650695290f965b563c5b5a55 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 25 Dec 2021 12:41:05 +0100 Subject: [PATCH] Message List: Drop redundant code --- src/components/middle/MessageList.tsx | 11 ++--------- src/components/middle/hooks/useScrollHooks.ts | 7 +------ src/components/ui/InfiniteScroll.tsx | 2 -- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index d78a88ed4..7127ecb2a 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -327,11 +327,6 @@ const MessageList: FC = ({ const container = containerRef.current!; listItemElementsRef.current = Array.from(container.querySelectorAll('.message-list-item')); - // TODO Consider removing - if (!container.offsetParent) { - return; - } - const hasLastMessageChanged = ( messageIds && prevMessageIds && messageIds[messageIds.length - 1] !== prevMessageIds[prevMessageIds.length - 1] ); @@ -362,8 +357,7 @@ const MessageList: FC = ({ } const { scrollTop, scrollHeight, offsetHeight } = container; - // TODO Consider `scrollOffset = scrollHeight - scrollTop` - const scrollOffset = scrollOffsetRef.current!; + const scrollOffset = scrollOffsetRef.current; const lastItemElement = listItemElementsRef.current[listItemElementsRef.current.length - 1]; let bottomOffset = scrollOffset - (prevContainerHeight || offsetHeight); @@ -405,8 +399,7 @@ const MessageList: FC = ({ } const isResized = prevContainerHeight !== undefined && prevContainerHeight !== containerHeight; - // TODO Look up within active transition slide - const anchor = anchorIdRef.current && document.getElementById(anchorIdRef.current); + const anchor = anchorIdRef.current && container.querySelector(`#${anchorIdRef.current}`); const unreadDivider = ( !anchor && memoUnreadDividerBeforeIdRef.current diff --git a/src/components/middle/hooks/useScrollHooks.ts b/src/components/middle/hooks/useScrollHooks.ts index 2a6a11aea..f7591019f 100644 --- a/src/components/middle/hooks/useScrollHooks.ts +++ b/src/components/middle/hooks/useScrollHooks.ts @@ -6,9 +6,8 @@ import { LoadMoreDirection } from '../../../types'; import { MessageListType } from '../../../global/types'; import { LOCAL_MESSAGE_ID_BASE, MESSAGE_LIST_SLICE } from '../../../config'; -import { IS_MAC_OS, IS_SCROLL_PATCH_NEEDED, MESSAGE_LIST_SENSITIVE_AREA } from '../../../util/environment'; +import { IS_SCROLL_PATCH_NEEDED, MESSAGE_LIST_SENSITIVE_AREA } from '../../../util/environment'; import { debounce } from '../../../util/schedulers'; -import resetScroll from '../../../util/resetScroll'; import { useIntersectionObserver, useOnIntersect } from '../../../hooks/useIntersectionObserver'; import useOnChange from '../../../hooks/useOnChange'; @@ -100,12 +99,8 @@ export default function useScrollHooks( isScrollPatchNeededRef.current = true; } - // TODO Consider removing - resetScroll(containerRef.current!); loadMoreBackwards(); } else if (target.className === 'forwards-trigger') { - // TODO Consider removing - resetScroll(containerRef.current!); loadMoreForwards(); } }); diff --git a/src/components/ui/InfiniteScroll.tsx b/src/components/ui/InfiniteScroll.tsx index 091f7c343..817415d06 100644 --- a/src/components/ui/InfiniteScroll.tsx +++ b/src/components/ui/InfiniteScroll.tsx @@ -165,7 +165,6 @@ const InfiniteScroll: FC = ({ stateRef.current.currentAnchor = nextAnchor; stateRef.current.currentAnchorTop = nextAnchorTop; isUpdated = true; - resetScroll(container); loadMoreForwards(); } } @@ -186,7 +185,6 @@ const InfiniteScroll: FC = ({ stateRef.current.currentAnchor = nextAnchor; stateRef.current.currentAnchorTop = nextAnchorTop; isUpdated = true; - resetScroll(container); loadMoreBackwards(); } }