PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 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 All 127 releases
extendify / src / Agent / Chat.jsx

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

96 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useCanvasSeat } from '@agent/components/Canvas';
2 import { DOMHighlighter } from '@agent/components/DOMHighlighter';
3 import { CanvasModalLayout } from '@agent/components/layouts/CanvasModalLayout';
4 import { DragResizeLayout } from '@agent/components/layouts/DragResizeLayout';
5 import { MobileLayout } from '@agent/components/layouts/MobileLayout';
6 import { DESKTOP_MIN_WIDTH, useGlobalStore } from '@agent/state/global';
7 import { useEditModeStore } from '@quick-edit/state/edit-mode';
8 import { useQuickEditStore } from '@quick-edit/state/store';
9 import { useEffect } from '@wordpress/element';
10 import { SidebarLayout } from './components/layouts/SidebarLayout';
11
12 export const Chat = ({ busy, working, children }) => {
13 const { setIsMobile, isMobile, mode } = useGlobalStore();
14 const canvasModal = useCanvasSeat() === 'modal';
15 const editModeOn = useEditModeStore((s) => s.on);
16 const block = useQuickEditStore((s) => s.agentBlock);
17 const setBlock = useQuickEditStore((s) => s.setAgentBlock);
18
19 useEffect(() => {
20 if (!isMobile || !block) return;
21 // Remove the block if we switch to mobile
22 setBlock(null);
23 }, [isMobile, setIsMobile, block, setBlock]);
24
25 useEffect(() => {
26 let timeout;
27 const onResize = () => {
28 clearTimeout(timeout);
29 timeout = window.setTimeout(() => {
30 setIsMobile(window.innerWidth < DESKTOP_MIN_WIDTH);
31 }, 10);
32 };
33 window.addEventListener('resize', onResize);
34 return () => {
35 clearTimeout(timeout);
36 window.removeEventListener('resize', onResize);
37 };
38 }, [setIsMobile]);
39
40 if (isMobile) {
41 return (
42 <MobileLayout>
43 <div
44 id="extendify-agent-chat"
45 className="flex min-h-0 flex-1 grow flex-col font-sans"
46 >
47 {children}
48 </div>
49 </MobileLayout>
50 );
51 }
52
53 if (canvasModal) {
54 return (
55 <>
56 {/* The docked panel holds the page's offset, so it stays behind. */}
57 {mode === 'docked-left' ? <SidebarLayout /> : null}
58 <CanvasModalLayout>
59 <div
60 id="extendify-agent-chat"
61 className="flex min-h-0 flex-1 grow flex-col font-sans"
62 >
63 {children}
64 </div>
65 </CanvasModalLayout>
66 </>
67 );
68 }
69
70 if (mode === 'docked-left') {
71 return (
72 <SidebarLayout>
73 <div
74 id="extendify-agent-chat"
75 className="flex min-h-0 flex-1 grow flex-col font-sans"
76 >
77 {children}
78 </div>
79 {editModeOn && <DOMHighlighter busy={busy} working={working} />}
80 </SidebarLayout>
81 );
82 }
83
84 return (
85 <DragResizeLayout>
86 <div
87 id="extendify-agent-chat"
88 className="flex min-h-0 flex-1 grow flex-col font-sans"
89 >
90 {children}
91 </div>
92 {editModeOn && <DOMHighlighter busy={busy} working={working} />}
93 </DragResizeLayout>
94 );
95 };
96