Page MenuHomePhabricator

No OneTemporary

diff --git a/web/selectors/thread-selectors.js b/web/selectors/thread-selectors.js
index 45d14945f..f573ec949 100644
--- a/web/selectors/thread-selectors.js
+++ b/web/selectors/thread-selectors.js
@@ -1,113 +1,115 @@
// @flow
import invariant from 'invariant';
import * as React from 'react';
import { useDispatch } from 'react-redux';
import { ENSCacheContext } from 'lib/components/ens-cache-provider.react.js';
import { createPendingSidebar } from 'lib/shared/thread-utils.js';
import type {
ComposableMessageInfo,
RobotextMessageInfo,
} from 'lib/types/message-types.js';
import type { ThreadInfo } from 'lib/types/thread-types.js';
import { getDefaultTextMessageRules } from '../markdown/rules.react.js';
import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
function useOnClickThread(
thread: ?ThreadInfo,
): (event: SyntheticEvent<HTMLElement>) => void {
const dispatch = useDispatch();
return React.useCallback(
(event: SyntheticEvent<HTMLElement>) => {
invariant(
thread?.id,
'useOnClickThread should be called with threadID set',
);
event.preventDefault();
const { id: threadID } = thread;
let payload;
if (threadID.includes('pending')) {
payload = {
chatMode: 'view',
activeChatThreadID: threadID,
pendingThread: thread,
+ tab: 'chat',
};
} else {
payload = {
chatMode: 'view',
activeChatThreadID: threadID,
+ tab: 'chat',
};
}
dispatch({ type: updateNavInfoActionType, payload });
},
[dispatch, thread],
);
}
function useThreadIsActive(threadID: string): boolean {
return useSelector(state => threadID === state.navInfo.activeChatThreadID);
}
function useOnClickPendingSidebar(
messageInfo: ComposableMessageInfo | RobotextMessageInfo,
threadInfo: ThreadInfo,
): (event: SyntheticEvent<HTMLElement>) => mixed {
const dispatch = useDispatch();
const viewerID = useSelector(state => state.currentUserInfo?.id);
const cacheContext = React.useContext(ENSCacheContext);
const { getENSNames } = cacheContext;
return React.useCallback(
async (event: SyntheticEvent<HTMLElement>) => {
event.preventDefault();
if (!viewerID) {
return;
}
const pendingSidebarInfo = await createPendingSidebar({
sourceMessageInfo: messageInfo,
parentThreadInfo: threadInfo,
viewerID,
markdownRules: getDefaultTextMessageRules().simpleMarkdownRules,
getENSNames,
});
dispatch({
type: updateNavInfoActionType,
payload: {
activeChatThreadID: pendingSidebarInfo.id,
pendingThread: pendingSidebarInfo,
},
});
},
[viewerID, messageInfo, threadInfo, dispatch, getENSNames],
);
}
function useOnClickNewThread(): (event: SyntheticEvent<HTMLElement>) => void {
const dispatch = useDispatch();
return React.useCallback(
(event: SyntheticEvent<HTMLElement>) => {
event.preventDefault();
dispatch({
type: updateNavInfoActionType,
payload: {
chatMode: 'create',
selectedUserList: [],
},
});
},
[dispatch],
);
}
export {
useOnClickThread,
useThreadIsActive,
useOnClickPendingSidebar,
useOnClickNewThread,
};

File Metadata

Mime Type
text/x-diff
Expires
Mon, Dec 23, 5:32 AM (18 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690407
Default Alt Text
(3 KB)

Event Timeline