Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32253684
D4916.1765238899.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D4916.1765238899.diff
View Options
diff --git a/web/chat/tooltip-utils.js b/web/chat/tooltip-utils.js
--- a/web/chat/tooltip-utils.js
+++ b/web/chat/tooltip-utils.js
@@ -3,6 +3,15 @@
import invariant from 'invariant';
import * as React from 'react';
+import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors';
+import { useSidebarExistsOrCanBeCreated } from 'lib/shared/thread-utils';
+import type { ThreadInfo } from 'lib/types/thread-types';
+
+import CommIcon from '../CommIcon.react';
+import {
+ useOnClickPendingSidebar,
+ useOnClickThread,
+} from '../selectors/nav-selectors';
import { calculateMaxTextWidth } from '../utils/text-utils';
import type { PositionInfo } from './position-types';
@@ -298,9 +307,50 @@
};
}
+function useMessageTooltipSidebarAction(
+ item: ChatMessageInfoItem,
+ threadInfo: ThreadInfo,
+): ?MessageTooltipAction {
+ const { threadCreatedFromMessage, messageInfo } = item;
+ const sidebarExists = !!threadCreatedFromMessage;
+ const sidebarExistsOrCanBeCreated = useSidebarExistsOrCanBeCreated(
+ threadInfo,
+ item,
+ );
+ const onThreadOpen = useOnClickThread(threadCreatedFromMessage);
+ const onPendingSidebarOpen = useOnClickPendingSidebar(
+ messageInfo,
+ threadInfo,
+ );
+ return React.useMemo(() => {
+ if (!sidebarExistsOrCanBeCreated) {
+ return null;
+ }
+ const buttonContent = <CommIcon icon="sidebar-filled" size={16} />;
+ const onClick = (event: SyntheticEvent<HTMLElement>) => {
+ if (threadCreatedFromMessage) {
+ onThreadOpen(event);
+ } else {
+ onPendingSidebarOpen(event);
+ }
+ };
+ return {
+ actionButtonContent: buttonContent,
+ onClick,
+ label: sidebarExists ? 'Go to thread' : 'Create thread',
+ };
+ }, [
+ onPendingSidebarOpen,
+ onThreadOpen,
+ sidebarExists,
+ sidebarExistsOrCanBeCreated,
+ threadCreatedFromMessage,
+ ]);
+}
export {
findTooltipPosition,
calculateTooltipSize,
getMessageActionTooltipStyle,
+ useMessageTooltipSidebarAction,
sizeOfTooltipArrow,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 9, 12:08 AM (6 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5851564
Default Alt Text
D4916.1765238899.diff (2 KB)
Attached To
Mode
D4916: [web] Introduce `useMessageTooltipSidebarAction` hook
Attached
Detach File
Event Timeline
Log In to Comment