|
1 | | -import React, { useState, useEffect } from "react"; |
| 1 | +import React, { useState, useEffect, useRef, useCallback } from "react"; |
2 | 2 | import { Layout, Menu, message, Button, Drawer } from "antd"; |
3 | 3 | import { |
4 | 4 | FolderOpenOutlined, |
@@ -32,6 +32,8 @@ function Views() { |
32 | 32 | const [visitedTabs, setVisitedTabs] = useState(new Set(["files"])); |
33 | 33 | const [workflowModalVisible, setWorkflowModalVisible] = useState(false); |
34 | 34 | const [isChatOpen, setIsChatOpen] = useState(false); |
| 35 | + const [chatWidth, setChatWidth] = useState(380); |
| 36 | + const isResizing = useRef(false); |
35 | 37 | const [apiReady, setApiReady] = useState(false); |
36 | 38 | const [hasShownApiWarning, setHasShownApiWarning] = useState(false); |
37 | 39 |
|
@@ -243,6 +245,33 @@ function Views() { |
243 | 245 | }; |
244 | 246 | }, [current]); |
245 | 247 |
|
| 248 | + const startResizing = useCallback((e) => { |
| 249 | + isResizing.current = true; |
| 250 | + e.preventDefault(); |
| 251 | + }, []); |
| 252 | + |
| 253 | + const stopResizing = useCallback(() => { |
| 254 | + isResizing.current = false; |
| 255 | + }, []); |
| 256 | + |
| 257 | + const resize = useCallback((e) => { |
| 258 | + if (isResizing.current) { |
| 259 | + const newWidth = window.innerWidth - e.clientX; |
| 260 | + if (newWidth >= 280 && newWidth <= 800) { |
| 261 | + setChatWidth(newWidth); |
| 262 | + } |
| 263 | + } |
| 264 | + }, []); |
| 265 | + |
| 266 | + useEffect(() => { |
| 267 | + window.addEventListener("mousemove", resize); |
| 268 | + window.addEventListener("mouseup", stopResizing); |
| 269 | + return () => { |
| 270 | + window.removeEventListener("mousemove", resize); |
| 271 | + window.removeEventListener("mouseup", stopResizing); |
| 272 | + }; |
| 273 | + }, [resize, stopResizing]); |
| 274 | + |
246 | 275 | const renderTabContent = (key, component) => { |
247 | 276 | if (!visitedTabs.has(key)) return null; |
248 | 277 | return ( |
@@ -320,12 +349,32 @@ function Views() { |
320 | 349 | placement="right" |
321 | 350 | open={isChatOpen} |
322 | 351 | onClose={() => setIsChatOpen(false)} |
323 | | - width={380} |
| 352 | + width={chatWidth} |
324 | 353 | mask={false} |
325 | 354 | closable={false} |
326 | 355 | destroyOnClose |
327 | 356 | styles={{ header: { display: "none" }, body: { padding: 0 } }} |
328 | 357 | > |
| 358 | + <div |
| 359 | + onMouseDown={startResizing} |
| 360 | + style={{ |
| 361 | + position: "absolute", |
| 362 | + left: 0, |
| 363 | + top: 0, |
| 364 | + bottom: 0, |
| 365 | + width: "4px", |
| 366 | + cursor: "ew-resize", |
| 367 | + backgroundColor: "transparent", |
| 368 | + zIndex: 10, |
| 369 | + }} |
| 370 | + onMouseEnter={(e) => |
| 371 | + (e.currentTarget.style.backgroundColor = "#1890ff") |
| 372 | + } |
| 373 | + onMouseLeave={(e) => |
| 374 | + !isResizing.current && |
| 375 | + (e.currentTarget.style.backgroundColor = "transparent") |
| 376 | + } |
| 377 | + /> |
329 | 378 | <Chatbot onClose={() => setIsChatOpen(false)} /> |
330 | 379 | </Drawer> |
331 | 380 | </Layout> |
|
0 commit comments