PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Agent / Chat.jsx

Chat.jsx in Extendify 2.2.0, at src/Agent/Chat.jsx

55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect } from '@wordpress/element';
2 import { DOMHighlighter } from '@agent/components/DOMHighlighter';
3 import { DragResizeLayout } from '@agent/components/layouts/DragResizeLayout';
4 import { MobileLayout } from '@agent/components/layouts/MobileLayout';
5 import { useGlobalStore } from '@agent/state/global';
6 import { useWorkflowStore } from '@agent/state/workflows';
7
8 export const Chat = ({ busy, children }) => {
9 const { setIsMobile, isMobile } = useGlobalStore();
10 const { domToolEnabled, block, setBlock } = useWorkflowStore();
11
12 useEffect(() => {
13 if (!isMobile || !block) return;
14 // Remove the block if we switch to mobile
15 setBlock(null);
16 }, [isMobile, setIsMobile, block, setBlock]);
17
18 useEffect(() => {
19 let timeout;
20 const onResize = () => {
21 clearTimeout(timeout);
22 timeout = window.setTimeout(() => {
23 setIsMobile(window.innerWidth < 783);
24 }, 10);
25 };
26 window.addEventListener('resize', onResize);
27 return () => {
28 clearTimeout(timeout);
29 window.removeEventListener('resize', onResize);
30 };
31 }, [setIsMobile]);
32
33 if (isMobile) {
34 return (
35 <MobileLayout>
36 <div
37 id="extendify-agent-chat"
38 className="flex min-h-0 flex-1 flex-grow flex-col font-sans">
39 {children}
40 </div>
41 </MobileLayout>
42 );
43 }
44 return (
45 <DragResizeLayout>
46 <div
47 id="extendify-agent-chat"
48 className="flex min-h-0 flex-1 flex-grow flex-col font-sans">
49 {children}
50 </div>
51 {domToolEnabled && <DOMHighlighter busy={busy} />}
52 </DragResizeLayout>
53 );
54 };
55