| 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 |
|