diff --git a/Frontend/src/components/Panel.jsx b/Frontend/src/components/Panel.jsx index b71f961..1b8d2aa 100644 --- a/Frontend/src/components/Panel.jsx +++ b/Frontend/src/components/Panel.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from "react"; -import { X } from "lucide-react"; +import { X, Maximize2, ChevronDown, Plus } from "lucide-react"; -const Panel = ({ +const Panel = ({ height, terminalOutput = [], isRunning = false, @@ -11,125 +11,135 @@ const Panel = ({ onClose, userInput = "", onUserInputChange, - onInputSubmit + onInputSubmit, }) => { const [activeTab, setActiveTab] = useState(initialTab); + const terminalRef = useRef(null); + const [inputBuffer, setInputBuffer] = useState(""); - // Set active tab when initialTab changes + // Update active tab when initialTab changes useEffect(() => { setActiveTab(initialTab); }, [initialTab]); - // Update the renderTerminal function to create an interactive terminal - const renderTerminal = () => { - const terminalRef = useRef(null); - const [inputBuffer, setInputBuffer] = useState(""); - - // Auto-scroll terminal to bottom when content changes - useEffect(() => { - if (terminalRef.current) { - terminalRef.current.scrollTop = terminalRef.current.scrollHeight; - } - }, [terminalOutput]); - - // Set up keyboard event listeners when terminal is focused - useEffect(() => { - const handleKeyDown = (e) => { - if (!isRunning) return; - - if (e.key === 'Enter') { - // Send current input buffer through WebSocket - if (inputBuffer.trim() && onInputSubmit) { - e.preventDefault(); // Prevent default Enter behavior - - // Important: Set user input and THEN call submit in a sequence - onUserInputChange(inputBuffer); - - // Add a small delay before submitting to ensure state update - setTimeout(() => { - onInputSubmit(); - // Clear buffer after submission is processed - setInputBuffer(""); - }, 10); - } - } else if (e.key === 'Backspace') { - // Handle backspace to remove characters - setInputBuffer(prev => prev.slice(0, -1)); - } else if (e.key.length === 1) { - // Add regular characters to input buffer - setInputBuffer(prev => prev + e.key); + // Auto-scroll terminal to the bottom when content changes + useEffect(() => { + if (terminalRef.current) { + terminalRef.current.scrollTop = terminalRef.current.scrollHeight; + } + }, [terminalOutput]); + + // Handle keyboard input for the terminal + useEffect(() => { + const handleKeyDown = (e) => { + if (!isRunning) return; + + if (e.key === "Enter") { + if (inputBuffer.trim() && onInputSubmit) { + e.preventDefault(); + onUserInputChange(inputBuffer); + setTimeout(() => { + onInputSubmit(); + setInputBuffer(""); + }, 10); } - }; - - // Add event listener - if (terminalRef.current) { - terminalRef.current.addEventListener('keydown', handleKeyDown); + } else if (e.key === "Backspace") { + setInputBuffer((prev) => prev.slice(0, -1)); + } else if (e.key.length === 1) { + setInputBuffer((prev) => prev + e.key); } - - // Clean up - return () => { - if (terminalRef.current) { - terminalRef.current.removeEventListener('keydown', handleKeyDown); - } - }; - }, [isRunning, inputBuffer, onInputSubmit, onUserInputChange]); - - return ( -