PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
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 3.1.4, at src/Agent/Chat.jsx

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