From 3956e9aff6e232b2e5c23383a622e3858acdc731 Mon Sep 17 00:00:00 2001 From: Burak Kocyigit Date: Fri, 10 Jan 2025 20:31:54 +0300 Subject: [PATCH 1/2] disable Run button when code is running --- frontend/src/components/code-editor/index.js | 36 +++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/code-editor/index.js b/frontend/src/components/code-editor/index.js index 5b9dd52..ea2e243 100644 --- a/frontend/src/components/code-editor/index.js +++ b/frontend/src/components/code-editor/index.js @@ -1,5 +1,5 @@ import { Editor } from "@monaco-editor/react"; -import { Box, Typography, useMediaQuery } from "@mui/material"; +import { Button,Box, Typography, useMediaQuery } from "@mui/material"; import { useEffect, useRef, useState } from "react"; import Menu from "@mui/material/Menu"; import MenuItem from "@mui/material/MenuItem"; @@ -32,6 +32,7 @@ const CodeEditor = ({ editorRef, }) => { const [value, setValue] = useState(null); + const [isRunning, setIsRunning] = useState(false); const [defaultValue, setDefaultValue] = useState(defValue); const [theme, setTheme] = useState("vs-dark"); const [editorActionsWidth, setEditorActionsWidth] = useState(0); @@ -47,6 +48,7 @@ const CodeEditor = ({ // here we will add the run calls const handleRun = async () => { + setIsRunning(true); onPending(true); // const toastId = toast.loading(t("runCode")); showToast("dismiss"); @@ -68,7 +70,9 @@ const CodeEditor = ({ toast.error(error.response?.data?.message || error.message, { id: 2 }); onRun(error.response?.data?.message || error.message); } + setIsRunning(false); onPending(false); + }; // here we will add the stop api calls @@ -196,6 +200,7 @@ const CodeEditor = ({ handleRun(); closeMobileMenu(); }} + disabled={isRunning} > - My SVG + Date: Fri, 10 Jan 2025 21:51:08 +0300 Subject: [PATCH 2/2] Lab output and errors configured --- frontend/src/views/lab-question.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/src/views/lab-question.js b/frontend/src/views/lab-question.js index 349dd83..9cdaf0a 100644 --- a/frontend/src/views/lab-question.js +++ b/frontend/src/views/lab-question.js @@ -122,8 +122,6 @@ const LabQuestion = ({ language = "", questionId }) => { difficulty: "", description: "", questionNote: "", - expectedOutputNote: "", - expectedOutput: "", hint: "", template: "", fileExtention: "", @@ -182,6 +180,10 @@ const LabQuestion = ({ language = "", questionId }) => { const editorRef = useRef(null); const dispatch = useDispatch(); + useEffect(() => { + console.log("Output:", output); + }, [output]); + const handleRun = (outputData) => { setOutput(outputData?.data); setIsSubmitted(true); @@ -220,6 +222,9 @@ const LabQuestion = ({ language = "", questionId }) => { }; const handleChange = (outputData) => { + setIsCorrect(false); + setIsFailed(false); + setIsSubmitted(false); setUserCode(outputData); }; @@ -253,8 +258,6 @@ const LabQuestion = ({ language = "", questionId }) => { difficulty: labSlice.data[0]?.difficulty, description: labSlice.data[0]?.language?.description, questionNote: labSlice.data[0]?.language?.note, - expectedOutputNote: labSlice.data[0]?.language?.expectedOutputNote, - expectedOutput: labSlice.data[0]?.language?.expectedOutput, hint: labSlice.data[0]?.language?.hint, template: labSlice.data[0]?.template, fileExtention: labSlice.data[0]?.fileExtention, @@ -345,7 +348,11 @@ const LabQuestion = ({ language = "", questionId }) => { - @@ -375,7 +382,7 @@ const LabQuestion = ({ language = "", questionId }) => { {/* Question Description */} {labData.description} - {output && output.output && ( + {((isCorrect || isFailed) && (output.output && output.expectedOutput)) ? ( { .replace("$$$", output.expectedOutput) .replace("***", output.output)}`} - )} + ) : null} {/* Question Note */} { )} - {isFailed && ( + {isFailed ? ( { > {t("labs.question.failed")} - )} + ) : null} {/* Expected output card */} {isSubmitted && (