Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3104430
D13823.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13823.id.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
@@ -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
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 31, 5:17 PM (20 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2393457
Default Alt Text
D13823.id.diff (4 KB)
Attached To
Mode
D13823: [lib][web] Introduce useCreateChatThreadItem
Attached
Detach File
Event Timeline
Log In to Comment