diff --git a/islands/Editor.tsx b/islands/Editor.tsx index cf9d9d4..a6d223f 100644 --- a/islands/Editor.tsx +++ b/islands/Editor.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "preact/hooks"; import { useToast } from "./useToast.ts"; -import { newPassSignal } from "./signals/store.ts" +import { newPassSignal } from "./signals/store.ts"; interface EditorProps { preCode: string; testingCode: string; @@ -29,7 +29,11 @@ export default function Editor(props: EditorProps) { const [output, setOutput] = useState(""); const [isError, setIsError] = useState(false); + const [testing, setTesting] = useState(false); + const [isTestPassed, setIsTestPassed] = useState( + undefined, + ); const { showToast } = useToast(); function handleCodeClear() { @@ -42,7 +46,7 @@ export default function Editor(props: EditorProps) { if (props.testingCode === "") { showToast( { - msg: "لا يوجد اختبارات لهذا السؤال", + msg: "لا يوجد اختبارات لهذا الدرس", type: "info", }, ); @@ -78,6 +82,8 @@ export default function Editor(props: EditorProps) { type: "success", }); newPassSignal.value = newPassSignal.value + 1; + setOutput("تم تجاوز الاختبارات بنجاح"); + setIsTestPassed(true); setTesting(false); return; } else { @@ -85,6 +91,8 @@ export default function Editor(props: EditorProps) { msg, type: "error", }); + setOutput(`${msg}`); + setIsTestPassed(false); setTesting(false); return; } @@ -93,6 +101,8 @@ export default function Editor(props: EditorProps) { msg: "لم يتم تجاوز الاختبارات", type: "error", }); + setOutput(`${error}`); + setIsTestPassed(false); setTesting(false); return; } @@ -101,6 +111,7 @@ export default function Editor(props: EditorProps) { function handleCodeRun() { const code: string | undefined = window.editor.getValue(); try { + setIsTestPassed(undefined); const capturedOutput: string[] = []; const originalConsoleLog = console.log; // deno-lint-ignore no-explicit-any @@ -155,7 +166,13 @@ export default function Editor(props: EditorProps) { مسح