Implement execution status polling and enhance input handling in EditorArea and Panel components

This commit is contained in:
2025-03-30 21:34:45 +05:30
parent 918b323cda
commit 1cbb4f3c35
3 changed files with 61 additions and 14 deletions

View File

@@ -168,6 +168,31 @@ const EditorArea = ({
}; };
}, []); }, []);
// Add interval to poll execution status
useEffect(() => {
const checkInterval = setInterval(() => {
// Poll execution status
if (activeSocket && activeRunningFile) {
// Check if socket is still connected
if (activeSocket.readyState !== WebSocket.OPEN) {
console.warn("Socket not in OPEN state:", activeSocket.readyState);
setTerminalOutput(prev => [...prev, {
type: 'warning',
content: `Terminal connection lost, attempting to reconnect...`
}]);
// Could implement reconnection logic here
}
}
}, 5000);
// Clean up interval when component unmounts
return () => {
if (checkInterval) {
clearInterval(checkInterval);
}
};
}, [activeSocket, activeRunningFile]);
const handleEditorDidMount = (editor) => { const handleEditorDidMount = (editor) => {
editorRef.current = editor; editorRef.current = editor;
}; };
@@ -738,22 +763,44 @@ This project is a VS Code Clone built with React and Monaco Editor. It features
}; };
// Update handleInputSubmit to ensure the input is sent properly // Update handleInputSubmit to ensure the input is sent properly
const handleInputSubmit = () => { const handleInputSubmit = (input) => {
// Log more detail for debugging // Use the direct input parameter instead of relying on userInput state
console.log("Input submit called, active socket:", !!activeSocket, "userInput:", userInput); const textToSend = input || userInput;
if (!activeSocket || !userInput.trim()) { console.log("Input submit called, active socket state:",
console.warn("Cannot send input: No active socket or empty input"); activeSocket ? activeSocket.readyState : "no socket",
"input:", textToSend);
if (!activeSocket) {
console.warn("Cannot send input: No active socket");
setTerminalOutput(prev => [...prev, {
type: 'warning',
content: `Cannot send input: No active connection`
}]);
return;
}
if (activeSocket.readyState !== WebSocket.OPEN) {
console.warn("Socket not in OPEN state:", activeSocket.readyState);
setTerminalOutput(prev => [...prev, {
type: 'warning',
content: `Cannot send input: Connection not open (state: ${activeSocket.readyState})`
}]);
return;
}
if (!textToSend.trim()) {
console.warn("Cannot send empty input");
return; return;
} }
try { try {
// Add the input to the terminal display // Add the input to the terminal display
setTerminalOutput(prev => [...prev, { type: 'command', content: `> ${userInput}` }]); setTerminalOutput(prev => [...prev, { type: 'command', content: `> ${textToSend}` }]);
// Send the input via WebSocket with a newline character to ensure it's processed // Send the input via WebSocket with a newline character
console.log("Sending input:", userInput); console.log("Sending input:", textToSend);
activeSocket.send(userInput + "\n"); activeSocket.send(textToSend + "\n");
// Clear the input field // Clear the input field
setUserInput(""); setUserInput("");

View File

@@ -37,11 +37,11 @@ const Panel = ({
if (e.key === "Enter") { if (e.key === "Enter") {
if (inputBuffer.trim() && onInputSubmit) { if (inputBuffer.trim() && onInputSubmit) {
e.preventDefault(); e.preventDefault();
onUserInputChange(inputBuffer); // Update parent's userInput state directly and call submit in the same function
setTimeout(() => { // instead of using setTimeout which creates a race condition
onInputSubmit(); onUserInputChange(inputBuffer);
setInputBuffer(""); onInputSubmit(inputBuffer); // Pass inputBuffer directly to avoid race condition
}, 10); setInputBuffer("");
} }
} else if (e.key === "Backspace") { } else if (e.key === "Backspace") {
setInputBuffer((prev) => prev.slice(0, -1)); setInputBuffer((prev) => prev.slice(0, -1));

Binary file not shown.