From 1cbb4f3c35040405627a10e3a366e76d66b2db29 Mon Sep 17 00:00:00 2001 From: Arnab-Afk Date: Sun, 30 Mar 2025 21:34:45 +0530 Subject: [PATCH] Implement execution status polling and enhance input handling in EditorArea and Panel components --- Frontend/src/components/EditorArea.jsx | 65 +++++++++++++++++++++---- Frontend/src/components/Panel.jsx | 10 ++-- backend/tmp/main.exe | Bin 8967168 -> 8967168 bytes 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/Frontend/src/components/EditorArea.jsx b/Frontend/src/components/EditorArea.jsx index a0610b5..caf0b2c 100644 --- a/Frontend/src/components/EditorArea.jsx +++ b/Frontend/src/components/EditorArea.jsx @@ -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) => { 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 - const handleInputSubmit = () => { - // Log more detail for debugging - console.log("Input submit called, active socket:", !!activeSocket, "userInput:", userInput); + const handleInputSubmit = (input) => { + // Use the direct input parameter instead of relying on userInput state + const textToSend = input || userInput; - if (!activeSocket || !userInput.trim()) { - console.warn("Cannot send input: No active socket or empty input"); + console.log("Input submit called, active socket state:", + 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; } try { // 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 - console.log("Sending input:", userInput); - activeSocket.send(userInput + "\n"); + // Send the input via WebSocket with a newline character + console.log("Sending input:", textToSend); + activeSocket.send(textToSend + "\n"); // Clear the input field setUserInput(""); diff --git a/Frontend/src/components/Panel.jsx b/Frontend/src/components/Panel.jsx index 791a710..a76a640 100644 --- a/Frontend/src/components/Panel.jsx +++ b/Frontend/src/components/Panel.jsx @@ -37,11 +37,11 @@ const Panel = ({ if (e.key === "Enter") { if (inputBuffer.trim() && onInputSubmit) { e.preventDefault(); - onUserInputChange(inputBuffer); - setTimeout(() => { - onInputSubmit(); - setInputBuffer(""); - }, 10); + // Update parent's userInput state directly and call submit in the same function + // instead of using setTimeout which creates a race condition + onUserInputChange(inputBuffer); + onInputSubmit(inputBuffer); // Pass inputBuffer directly to avoid race condition + setInputBuffer(""); } } else if (e.key === "Backspace") { setInputBuffer((prev) => prev.slice(0, -1)); diff --git a/backend/tmp/main.exe b/backend/tmp/main.exe index ccc2eba2af732c57dc3937a2bf7d050a610c0661..2eedd682f09074c8d4143cecadd503b7bbeef6e9 100644 GIT binary patch delta 1138 zcmci7NlX)Q6bA5?rBXmdP{FDQ1vhNzbh=2dCA}FryppHw7 zO-%fwF~($Qs`1i;$sA0K9*jm0aPVT{fdd#4V`9{U7owjR_2kjR@ABon_vIxX$ax9K zmTJ2CIU#1W2mKyzYbP7^?(uQ%7LzN|7IzJBhx=V@B(+!kg# zhEEQ*4z>HcOufdop}0SMii*aaEZx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