Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3511185
D14141.id46360.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D14141.id46360.diff
View Options
diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js
--- a/lib/selectors/chat-selectors.js
+++ b/lib/selectors/chat-selectors.js
@@ -79,7 +79,7 @@
);
}
-type ChatThreadItemLoader = {
+export type ChatThreadItemLoader = {
+threadInfo: ThreadInfo,
+lastUpdatedAtLeastTimeIncludingSidebars: number,
+lastUpdatedAtMostTimeIncludingSidebars: number,
@@ -185,15 +185,36 @@
return useChatThreadItems(filteredThreadInfos);
}
-const sortFunc = _orderBy('lastUpdatedTimeIncludingSidebars')('desc');
-function useChatThreadItems(
+function useFlattenedChatListLoaders(): $ReadOnlyArray<ChatThreadItemLoader> {
+ return useFilteredChatListLoaders(threadInChatList);
+}
+
+function useFilteredChatListLoaders(
+ filterFunction: (threadInfo: ?(ThreadInfo | RawThreadInfo)) => boolean,
+): $ReadOnlyArray<ChatThreadItemLoader> {
+ const threadInfos = useSelector(threadInfoSelector);
+ const filteredThreadInfos = React.useMemo(
+ () => Object.values(threadInfos).filter(filterFunction),
+ [threadInfos, filterFunction],
+ );
+ return useChatThreadItemLoaders(filteredThreadInfos);
+}
+
+function useChatThreadItemLoaders(
threadInfos: $ReadOnlyArray<ThreadInfo>,
-): $ReadOnlyArray<ChatThreadItem> {
+): $ReadOnlyArray<ChatThreadItemLoader> {
const getChatThreadItemLoader = useGetChatThreadItemLoader();
- const chatThreadItemLoaders = React.useMemo(
+ return React.useMemo(
() => threadInfos.map(getChatThreadItemLoader),
[threadInfos, getChatThreadItemLoader],
);
+}
+
+const sortFunc = _orderBy('lastUpdatedTimeIncludingSidebars')('desc');
+function useChatThreadItems(
+ threadInfos: $ReadOnlyArray<ThreadInfo>,
+): $ReadOnlyArray<ChatThreadItem> {
+ const chatThreadItemLoaders = useChatThreadItemLoaders(threadInfos);
const initialChatThreadItems = React.useMemo(
() => chatThreadItemLoaders.map(loader => loader.initialChatThreadItem),
@@ -756,6 +777,7 @@
messageListData,
useFlattenedChatListData,
useFilteredChatListData,
+ useFlattenedChatListLoaders,
useChatThreadItems,
useMessageListData,
};
diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js
--- a/native/chat/chat-thread-list.react.js
+++ b/native/chat/chat-thread-list.react.js
@@ -26,7 +26,7 @@
import { useThreadListSearch } from 'lib/hooks/thread-search-hooks.js';
import {
type ChatThreadItem,
- useFlattenedChatListData,
+ useFlattenedChatListLoaders,
} from 'lib/selectors/chat-selectors.js';
import {
createPendingThread,
@@ -35,6 +35,10 @@
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
import type { UserInfo } from 'lib/types/user-types.js';
+import {
+ ChatThreadItemLoaderCache,
+ defaultNumItemsToDisplay,
+} from 'lib/utils/chat-thread-item-loader-cache.js';
import { ChatThreadListItem } from './chat-thread-list-item.react.js';
import ChatThreadListSearch from './chat-thread-list-search.react.js';
@@ -83,7 +87,16 @@
export type SearchStatus = 'inactive' | 'activating' | 'active';
function ChatThreadList(props: BaseProps): React.Node {
- const boundChatListData = useFlattenedChatListData();
+ const chatThreadItemLoaders = useFlattenedChatListLoaders();
+ const chatThreadItemLoaderCache = React.useMemo(
+ () => new ChatThreadItemLoaderCache(chatThreadItemLoaders),
+ [chatThreadItemLoaders],
+ );
+
+ const [boundChatListData, setBoundChatListData] = React.useState<
+ $ReadOnlyArray<ChatThreadItem>,
+ >(() => chatThreadItemLoaderCache.getAllChatThreadItems());
+
const loggedInUserInfo = useLoggedInUserInfo();
const styles = useStyles(unboundStyles);
const indicatorStyle = useSelector(indicatorStyleSelector);
@@ -102,11 +115,23 @@
);
const [openedSwipeableID, setOpenedSwipeableID] = React.useState<string>('');
- const [numItemsToDisplay, setNumItemsToDisplay] = React.useState<number>(25);
+ const [numItemsToDisplay, setNumItemsToDisplay] = React.useState<number>(
+ defaultNumItemsToDisplay,
+ );
+
+ React.useEffect(() => {
+ void (async () => {
+ const results =
+ await chatThreadItemLoaderCache.loadMostRecentChatThreadItems(
+ numItemsToDisplay,
+ );
+ setBoundChatListData(results);
+ })();
+ }, [numItemsToDisplay, chatThreadItemLoaderCache]);
const onChangeSearchText = React.useCallback((updatedSearchText: string) => {
setSearchText(updatedSearchText);
- setNumItemsToDisplay(25);
+ setNumItemsToDisplay(defaultNumItemsToDisplay);
}, []);
const scrollPos = React.useRef(0);
@@ -314,7 +339,9 @@
if (partialListData.length === listData.length) {
return;
}
- setNumItemsToDisplay(prevNumItems => prevNumItems + 25);
+ setNumItemsToDisplay(
+ prevNumItems => prevNumItems + defaultNumItemsToDisplay,
+ );
}, [listData.length, partialListData.length]);
const floatingAction = React.useMemo(() => {
@@ -417,7 +444,7 @@
React.useEffect(() => {
const clearNavigationBlurListener = navigation.addListener('blur', () => {
- setNumItemsToDisplay(25);
+ setNumItemsToDisplay(defaultNumItemsToDisplay);
});
return () => {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 22, 1:39 PM (10 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2691560
Default Alt Text
D14141.id46360.diff (5 KB)
Attached To
Mode
D14141: [lib][native] Update native to use ChatThreadItemLoaderCache
Attached
Detach File
Event Timeline
Log In to Comment