Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3509864
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/web/selectors/thread-selectors.js b/web/selectors/thread-selectors.js
index 64e5d5684..dd783516a 100644
--- a/web/selectors/thread-selectors.js
+++ b/web/selectors/thread-selectors.js
@@ -1,116 +1,129 @@
// @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 { useLoggedInUserInfo } from 'lib/hooks/account-hooks.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 loggedInUserInfo = useLoggedInUserInfo();
const cacheContext = React.useContext(ENSCacheContext);
const { getENSNames } = cacheContext;
return React.useCallback(
async (event: SyntheticEvent<HTMLElement>) => {
event.preventDefault();
if (!loggedInUserInfo) {
return;
}
const pendingSidebarInfo = await createPendingSidebar({
sourceMessageInfo: messageInfo,
parentThreadInfo: threadInfo,
loggedInUserInfo,
markdownRules: getDefaultTextMessageRules().simpleMarkdownRules,
getENSNames,
});
dispatch({
type: updateNavInfoActionType,
payload: {
activeChatThreadID: pendingSidebarInfo.id,
pendingThread: pendingSidebarInfo,
},
});
},
[loggedInUserInfo, 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],
);
}
+function useDrawerSelectedThreadID(): ?string {
+ const activeChatThreadID = useSelector(
+ state => state.navInfo.activeChatThreadID,
+ );
+ const pickedCommunityID = useSelector(
+ state => state.calendarPickedCommunityID,
+ );
+ const inCalendar = useSelector(state => state.navInfo.tab === 'calendar');
+
+ return inCalendar ? pickedCommunityID : activeChatThreadID;
+}
+
export {
useOnClickThread,
useThreadIsActive,
useOnClickPendingSidebar,
useOnClickNewThread,
+ useDrawerSelectedThreadID,
};
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Dec 23, 8:59 AM (20 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690678
Default Alt Text
(3 KB)
Attached To
Mode
rCOMM Comm
Attached
Detach File
Event Timeline
Log In to Comment