diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 66cc119..cd68474 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -31,7 +31,7 @@ import { UrlInputSection } from "./components/UrlInputSection"; import TermsOfServiceDialog from "./components/TermsOfServiceDialog"; import html2canvas from "html2canvas"; import { USER_CLOSE_WEB_SOCKET_CODE } from "./constants"; -import { handleInstructions } from "./lib/utils"; +import { calculateMistakesNum, handleInstructions } from "./lib/utils"; function App() { const [appState, setAppState] = useState(AppState.INITIAL); @@ -52,6 +52,7 @@ function App() { ); const [shouldIncludeResultImage, setShouldIncludeResultImage] = useState(false); + const [mistakesNum, setMistakesNum] = useState(0); const wsRef = useRef(null); const takeScreenshot = async (): Promise => { @@ -118,7 +119,7 @@ function App() { function doGenerateInstruction(params: InstructionGenerationParams) { setAppState(AppState.INSTRUCTION_GENERATING); setUpdateInstruction(""); - + setMistakesNum(0); // Merge settings with params const updatedParams = { ...params, ...settings }; @@ -129,8 +130,13 @@ function App() { (code) => setUpdateInstruction(code), (line) => setExecutionConsole((prev) => [...prev, line]), () => { - setUpdateInstruction(instruction => handleInstructions(instruction)); setAppState(AppState.CODE_READY); + setUpdateInstruction(instruction => { + setMistakesNum(calculateMistakesNum(instruction)); + handleInstructions(instruction); + return instruction; + }); + } ); } @@ -243,6 +249,7 @@ function App() { onChange={(e) => setUpdateInstruction(e.target.value)} value={updateInstruction} disabled={appState === AppState.INSTRUCTION_GENERATING} + />
@@ -284,7 +291,7 @@ function App() { {/* Reference image display */}
-
+
Original Screenshot
+
+ Total Mistakes Found:{" "} {mistakesNum} +

diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index c6010cb..e0e92c8 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -10,3 +10,5 @@ export const handleInstructions = (instructions: string): string => (JSON.parse(instructions) || []).map((line: Instruction) => `- ${line.element} in the ${line.location} has a mistake: ${line.mistake}, please update: ${line.improvement}.`).join("\n\n"); +export const calculateMistakesNum = (instructions: string): number => + (JSON.parse(instructions) || []).length; \ No newline at end of file