Page MenuHomePhabricator

D13823.id45473.diff
No OneTemporary

D13823.id45473.diff

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
@@ -200,6 +200,22 @@
};
}
+function useCreateChatThreadItem(): ThreadInfo => ChatThreadItem {
+ const messageInfos = useSelector(messageInfoSelector);
+ const sidebarInfos = useSelector(sidebarInfoSelector);
+ const messageStore = useSelector(state => state.messageStore);
+ return React.useCallback(
+ threadInfo =>
+ createChatThreadItem(
+ threadInfo,
+ messageStore,
+ messageInfos,
+ sidebarInfos[threadInfo.id],
+ ),
+ [messageInfos, messageStore, sidebarInfos],
+ );
+}
+
function useFlattenedChatListData(): $ReadOnlyArray<ChatThreadItem> {
return useFilteredChatListData(threadInChatList);
}
@@ -208,25 +224,15 @@
filterFunction: (threadInfo: ?(ThreadInfo | RawThreadInfo)) => boolean,
): $ReadOnlyArray<ChatThreadItem> {
const threadInfos = useSelector(threadInfoSelector);
- const messageInfos = useSelector(messageInfoSelector);
- const sidebarInfos = useSelector(sidebarInfoSelector);
- const messageStore = useSelector(state => state.messageStore);
-
+ const getChatThreadItem = useCreateChatThreadItem();
return React.useMemo(
() =>
_flow(
_filter(filterFunction),
- _map((threadInfo: ThreadInfo): ChatThreadItem =>
- createChatThreadItem(
- threadInfo,
- messageStore,
- messageInfos,
- sidebarInfos[threadInfo.id],
- ),
- ),
+ _map(getChatThreadItem),
_orderBy('lastUpdatedTimeIncludingSidebars')('desc'),
)(threadInfos),
- [messageInfos, messageStore, sidebarInfos, filterFunction, threadInfos],
+ [getChatThreadItem, filterFunction, threadInfos],
);
}
@@ -692,7 +698,7 @@
export {
messageInfoSelector,
- createChatThreadItem,
+ useCreateChatThreadItem,
createChatMessageItems,
messageListData,
useFlattenedChatListData,
diff --git a/web/selectors/chat-selectors.js b/web/selectors/chat-selectors.js
--- a/web/selectors/chat-selectors.js
+++ b/web/selectors/chat-selectors.js
@@ -4,10 +4,8 @@
import {
type ChatThreadItem,
- createChatThreadItem,
- messageInfoSelector,
+ useCreateChatThreadItem,
} from 'lib/selectors/chat-selectors.js';
-import { sidebarInfoSelector } from 'lib/selectors/sidebar-selectors.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
import { threadIsPending } from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
@@ -15,36 +13,22 @@
import { useSelector } from '../redux/redux-utils.js';
function useChatThreadItem(threadInfo: ?ThreadInfo): ?ChatThreadItem {
- const messageInfos = useSelector(messageInfoSelector);
- const sidebarInfos = useSelector(sidebarInfoSelector);
- const messageStore = useSelector(state => state.messageStore);
-
+ const createChatThreadItem = useCreateChatThreadItem();
return React.useMemo(() => {
if (!threadInfo) {
return null;
}
-
- return createChatThreadItem(
- threadInfo,
- messageStore,
- messageInfos,
- sidebarInfos[threadInfo.id],
- );
- }, [messageInfos, messageStore, sidebarInfos, threadInfo]);
+ return createChatThreadItem(threadInfo);
+ }, [createChatThreadItem, threadInfo]);
}
function useActiveChatThreadItem(): ?ChatThreadItem {
- const messageInfos = useSelector(messageInfoSelector);
- const sidebarInfos = useSelector(sidebarInfoSelector);
- const messageStore = useSelector(state => state.messageStore);
-
+ const createChatThreadItem = useCreateChatThreadItem();
const activeChatThreadID = useSelector(
state => state.navInfo.activeChatThreadID,
);
const pendingThreadInfo = useSelector(state => state.navInfo.pendingThread);
-
const threadInfos = useSelector(threadInfoSelector);
-
return React.useMemo(() => {
if (!activeChatThreadID) {
return null;
@@ -53,20 +37,12 @@
const threadInfo = isPending
? pendingThreadInfo
: threadInfos[activeChatThreadID];
-
if (!threadInfo) {
return null;
}
- return createChatThreadItem(
- threadInfo,
- messageStore,
- messageInfos,
- sidebarInfos[threadInfo.id],
- );
+ return createChatThreadItem(threadInfo);
}, [
- messageInfos,
- sidebarInfos,
- messageStore,
+ createChatThreadItem,
activeChatThreadID,
pendingThreadInfo,
threadInfos,

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 5:18 PM (20 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2393457
Default Alt Text
D13823.id45473.diff (4 KB)

Event Timeline