({ consoleOutputs, setConsoleOutputs }: ConsoleProps)
| 28 | } |
| 29 | |
| 30 | export function Console({ consoleOutputs, setConsoleOutputs }: ConsoleProps) { |
| 31 | const [height, setHeight] = useState<number>(300); |
| 32 | const [isResizing, setIsResizing] = useState(false); |
| 33 | const consoleEndRef = useRef<HTMLDivElement>(null); |
| 34 | |
| 35 | const isArtifactVisible = useArtifactSelector((state) => state.isVisible); |
| 36 | |
| 37 | const minHeight = 100; |
| 38 | const maxHeight = 800; |
| 39 | |
| 40 | const startResizing = useCallback(() => { |
| 41 | setIsResizing(true); |
| 42 | }, []); |
| 43 | |
| 44 | const stopResizing = useCallback(() => { |
| 45 | setIsResizing(false); |
| 46 | }, []); |
| 47 | |
| 48 | const resize = useCallback( |
| 49 | (e: MouseEvent) => { |
| 50 | if (isResizing) { |
| 51 | const newHeight = window.innerHeight - e.clientY; |
| 52 | if (newHeight >= minHeight && newHeight <= maxHeight) { |
| 53 | setHeight(newHeight); |
| 54 | } |
| 55 | } |
| 56 | }, |
| 57 | [isResizing], |
| 58 | ); |
| 59 | |
| 60 | useEffect(() => { |
| 61 | window.addEventListener('mousemove', resize); |
| 62 | window.addEventListener('mouseup', stopResizing); |
| 63 | return () => { |
| 64 | window.removeEventListener('mousemove', resize); |
| 65 | window.removeEventListener('mouseup', stopResizing); |
| 66 | }; |
| 67 | }, [resize, stopResizing]); |
| 68 | |
| 69 | useEffect(() => { |
| 70 | consoleEndRef.current?.scrollIntoView({ behavior: 'smooth' }); |
| 71 | }, [consoleOutputs]); |
| 72 | |
| 73 | useEffect(() => { |
| 74 | if (!isArtifactVisible) { |
| 75 | setConsoleOutputs([]); |
| 76 | } |
| 77 | }, [isArtifactVisible, setConsoleOutputs]); |
| 78 | |
| 79 | return consoleOutputs.length > 0 ? ( |
| 80 | <> |
| 81 | <div |
| 82 | className="h-2 w-full fixed cursor-ns-resize z-50" |
| 83 | onMouseDown={startResizing} |
| 84 | style={{ bottom: height - 4 }} |
| 85 | role="slider" |
| 86 | aria-valuenow={minHeight} |
| 87 | /> |
nothing calls this directly
no test coverage detected
searching dependent graphs…