Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3105360
D13822.id45472.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
D13822.id45472.diff
View Options
diff --git a/web/avatars/web-edit-thread-avatar-provider.react.js b/web/avatars/web-edit-thread-avatar-provider.react.js
--- a/web/avatars/web-edit-thread-avatar-provider.react.js
+++ b/web/avatars/web-edit-thread-avatar-provider.react.js
@@ -4,15 +4,14 @@
import { BaseEditThreadAvatarProvider } from 'lib/components/base-edit-thread-avatar-provider.react.js';
-import { useSelector } from '../redux/redux-utils.js';
-import { activeChatThreadItem as activeChatThreadItemSelector } from '../selectors/chat-selectors.js';
+import { useActiveChatThreadItem } from '../selectors/chat-selectors.js';
type Props = {
+children: React.Node,
};
function WebEditThreadAvatarProvider(props: Props): React.Node {
const { children } = props;
- const activeChatThreadItem = useSelector(activeChatThreadItemSelector);
+ const activeChatThreadItem = useActiveChatThreadItem();
const activeThreadID = activeChatThreadItem?.threadInfo?.id ?? '';
return (
diff --git a/web/chat/thread-list-provider.js b/web/chat/thread-list-provider.js
--- a/web/chat/thread-list-provider.js
+++ b/web/chat/thread-list-provider.js
@@ -22,7 +22,7 @@
import { useSelector } from '../redux/redux-utils.js';
import {
useChatThreadItem,
- activeChatThreadItem as activeChatThreadItemSelector,
+ useActiveChatThreadItem,
} from '../selectors/chat-selectors.js';
type ChatTabType = 'Home' | 'Muted';
@@ -43,7 +43,7 @@
function ThreadListProvider(props: ThreadListProviderProps): React.Node {
const [activeTab, setActiveTab] = React.useState('Home');
- const activeChatThreadItem = useSelector(activeChatThreadItemSelector);
+ const activeChatThreadItem = useActiveChatThreadItem();
const activeThreadInfo = activeChatThreadItem?.threadInfo;
const activeThreadID = activeThreadInfo?.id;
const activeSidebarParentThreadInfo = useSelector(state => {
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
@@ -1,7 +1,6 @@
// @flow
import * as React from 'react';
-import { createSelector } from 'reselect';
import {
type ChatThreadItem,
@@ -11,51 +10,10 @@
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 { MessageInfo, MessageStore } from 'lib/types/message-types.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
-import type { SidebarInfo } from 'lib/types/thread-types.js';
-import type { AppState } from '../redux/redux-setup.js';
import { useSelector } from '../redux/redux-utils.js';
-const activeChatThreadItem: (state: AppState) => ?ChatThreadItem =
- createSelector(
- threadInfoSelector,
- (state: AppState) => state.messageStore,
- messageInfoSelector,
- (state: AppState) => state.navInfo.activeChatThreadID,
- (state: AppState) => state.navInfo.pendingThread,
- sidebarInfoSelector,
- (
- threadInfos: {
- +[id: string]: ThreadInfo,
- },
- messageStore: MessageStore,
- messageInfos: { +[id: string]: ?MessageInfo },
- activeChatThreadID: ?string,
- pendingThreadInfo: ?ThreadInfo,
- sidebarInfos: { +[id: string]: $ReadOnlyArray<SidebarInfo> },
- ): ?ChatThreadItem => {
- if (!activeChatThreadID) {
- return null;
- }
- const isPending = threadIsPending(activeChatThreadID);
- const threadInfo = isPending
- ? pendingThreadInfo
- : threadInfos[activeChatThreadID];
-
- if (!threadInfo) {
- return null;
- }
- return createChatThreadItem(
- threadInfo,
- messageStore,
- messageInfos,
- sidebarInfos[threadInfo.id],
- );
- },
- );
-
function useChatThreadItem(threadInfo: ?ThreadInfo): ?ChatThreadItem {
const messageInfos = useSelector(messageInfoSelector);
const sidebarInfos = useSelector(sidebarInfoSelector);
@@ -74,4 +32,45 @@
);
}, [messageInfos, messageStore, sidebarInfos, threadInfo]);
}
-export { useChatThreadItem, activeChatThreadItem };
+
+function useActiveChatThreadItem(): ?ChatThreadItem {
+ const messageInfos = useSelector(messageInfoSelector);
+ const sidebarInfos = useSelector(sidebarInfoSelector);
+ const messageStore = useSelector(state => state.messageStore);
+
+ 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;
+ }
+ const isPending = threadIsPending(activeChatThreadID);
+ const threadInfo = isPending
+ ? pendingThreadInfo
+ : threadInfos[activeChatThreadID];
+
+ if (!threadInfo) {
+ return null;
+ }
+ return createChatThreadItem(
+ threadInfo,
+ messageStore,
+ messageInfos,
+ sidebarInfos[threadInfo.id],
+ );
+ }, [
+ messageInfos,
+ sidebarInfos,
+ messageStore,
+ activeChatThreadID,
+ pendingThreadInfo,
+ threadInfos,
+ ]);
+}
+
+export { useChatThreadItem, useActiveChatThreadItem };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 31, 10:32 PM (22 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2393460
Default Alt Text
D13822.id45472.diff (5 KB)
Attached To
Mode
D13822: [web] Convert activeChatThreadItem to a hook
Attached
Detach File
Event Timeline
Log In to Comment