(props: { trademark: boolean })
| 30 | import AIChatSuggestedQuestions from './AIChatSuggestedQuestions'; |
| 31 | |
| 32 | export function AIChat(props: { trademark: boolean }) { |
| 33 | const { trademark } = props; |
| 34 | |
| 35 | const language = useLanguage(); |
| 36 | const chat = useAIChatState(); |
| 37 | const chatController = useAIChatController(); |
| 38 | const containerRef = React.useRef<HTMLDivElement>(null); |
| 39 | |
| 40 | // When the chat is opened, scroll to it (applicable on mobile, where it's displayed above the content) |
| 41 | React.useEffect(() => { |
| 42 | if (chat.opened) { |
| 43 | containerRef.current?.scrollIntoView({ |
| 44 | behavior: 'smooth', |
| 45 | block: 'start', |
| 46 | }); |
| 47 | } |
| 48 | }, [chat.opened]); |
| 49 | |
| 50 | useHotkeys( |
| 51 | 'esc', |
| 52 | () => { |
| 53 | chatController.close(); |
| 54 | }, |
| 55 | [] |
| 56 | ); |
| 57 | |
| 58 | // Track the view of the AI chat |
| 59 | const trackEvent = useTrackEvent(); |
| 60 | React.useEffect(() => { |
| 61 | if (chat.opened) { |
| 62 | trackEvent({ |
| 63 | type: 'ask_view', |
| 64 | }); |
| 65 | } |
| 66 | }, [chat.opened, trackEvent]); |
| 67 | |
| 68 | if (!chat.opened) { |
| 69 | return null; |
| 70 | } |
| 71 | |
| 72 | return ( |
| 73 | <div |
| 74 | data-testid="ai-chat" |
| 75 | className="ai-chat inset-y-0 right-0 z-40 mx-auto flex max-w-3xl animate-present scroll-mt-36 px-4 py-4 transition-all duration-300 sm:px-6 lg:fixed lg:w-80 lg:animate-enter-from-right lg:pr-4 lg:pl-0 xl:w-96" |
| 76 | > |
| 77 | <EmbeddableFrame className="relative circular-corners:rounded-3xl rounded-corners:rounded-md depth-subtle:shadow-lg shadow-tint ring-1 ring-tint-subtle"> |
| 78 | <EmbeddableFrameHeader> |
| 79 | <AIChatDynamicIcon trademark={trademark} /> |
| 80 | <EmbeddableFrameHeaderMain> |
| 81 | <EmbeddableFrameTitle> |
| 82 | {getAIChatName(language, trademark)} |
| 83 | </EmbeddableFrameTitle> |
| 84 | <AIChatSubtitle chat={chat} /> |
| 85 | </EmbeddableFrameHeaderMain> |
| 86 | <EmbeddableFrameButtons> |
| 87 | <AIChatControlButton /> |
| 88 | <Button |
| 89 | onClick={() => chatController.close()} |
nothing calls this directly
no test coverage detected