Page MenuHomePhorge

D8235.1768807120.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D8235.1768807120.diff

diff --git a/web/chat/chat-thread-list.react.js b/web/chat/chat-thread-list.react.js
--- a/web/chat/chat-thread-list.react.js
+++ b/web/chat/chat-thread-list.react.js
@@ -6,6 +6,7 @@
import AutoSizer from 'react-virtualized-auto-sizer';
import { VariableSizeList } from 'react-window';
+import { useFetchLatestMessages } from 'lib/hooks/message-hooks.js';
import { emptyItemText } from 'lib/shared/thread-utils.js';
import ChatThreadListItem from './chat-thread-list-item.react.js';
@@ -17,6 +18,8 @@
import { useSelector } from '../redux/redux-utils.js';
import { useOnClickNewThread } from '../selectors/thread-selectors.js';
+const prefetchMessagesThreadThreshold = 5;
+
const sizes = {
search: 68,
thread: 81,
@@ -66,6 +69,10 @@
[searchText, setSearchText],
);
+ const { fetchMoreLatestMessages, loadingStatus } = useFetchLatestMessages(
+ activeTab === 'Focus',
+ );
+
const threadListContainerRef = React.useRef();
const threads = React.useMemo(
@@ -79,6 +86,29 @@
[communityID, threadList],
);
+ const [currentHeight, setCurrentHeight] = React.useState(0);
+ React.useEffect(() => {
+ if (loadingStatus === 'loading') {
+ return;
+ }
+
+ let totalHeight = sizes.search;
+ for (const threadItem of threads) {
+ totalHeight += getThreadItemSize(threadItem);
+ if (totalHeight > currentHeight) {
+ return;
+ }
+ }
+
+ fetchMoreLatestMessages();
+ }, [
+ currentHeight,
+ fetchMoreLatestMessages,
+ loadingStatus,
+ threads,
+ threads.length,
+ ]);
+
React.useEffect(() => {
if (threadListContainerRef.current) {
threadListContainerRef.current.resetAfterIndex(0, false);
@@ -108,8 +138,20 @@
return getThreadItemSize(items[index]);
};
+ const onItemsRendered = ({ visibleStopIndex }) => {
+ if (
+ visibleStopIndex >= threads.length - prefetchMessagesThreadThreshold &&
+ loadingStatus !== 'loading'
+ ) {
+ fetchMoreLatestMessages();
+ }
+ };
+
return (
- <AutoSizer disableWidth>
+ <AutoSizer
+ disableWidth
+ onResize={({ height }) => setCurrentHeight(height)}
+ >
{({ height }) => (
<VariableSizeList
itemData={items}
@@ -118,6 +160,7 @@
itemKey={itemKey}
height={height}
overscanCount={1}
+ onItemsRendered={onItemsRendered}
ref={threadListContainerRef}
>
{renderItem}
@@ -125,7 +168,7 @@
)}
</AutoSizer>
);
- }, [isBackground, search, threads]);
+ }, [fetchMoreLatestMessages, isBackground, loadingStatus, search, threads]);
return (
<>

File Metadata

Mime Type
text/plain
Expires
Mon, Jan 19, 7:18 AM (2 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5955134
Default Alt Text
D8235.1768807120.diff (2 KB)

Event Timeline