diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 2cbe4b1..75e2b02 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -50,57 +50,59 @@ function AppRoutes() { } const { isAuthenticated } = authContext; return ( - - {/* Public routes */} - : - } - /> - } /> - } /> - } /> - {/* Protected routes with layout */} - }> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } - /> - } - /> - } /> - } - />{' '} - {/* Add this route */} - } /> + + {/* Public routes */} + : + } + /> + } /> + } /> + } /> + + {/* Protected routes */} + }> + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } + /> + + {/* Coach routes */} + }> + } + /> + } /> + + + + {/* Debate routes (outside layout) */} + } /> + } /> + } /> + } /> + } /> + } /> + } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - {/* Redirect unknown routes */} - } /> - + + {/* Redirect unknown routes */} + } /> + + ); } diff --git a/frontend/src/Pages/DebateRoom.tsx b/frontend/src/Pages/DebateRoom.tsx index c2ed137..b078848 100644 --- a/frontend/src/Pages/DebateRoom.tsx +++ b/frontend/src/Pages/DebateRoom.tsx @@ -217,6 +217,8 @@ const extractJSON = (response: string): string => { }; const DebateRoom: React.FC = () => { + const judgingRef = useRef(false); + const navigate = useNavigate(); const location = useLocation(); const navigate = useNavigate(); const debateData = location.state as DebateProps; @@ -574,50 +576,56 @@ const DebateRoom: React.FC = () => { } }; - const judgeDebateResult = async (messages: Message[]) => { + const judgeDebateResult = async (messages: Message[]) => { + if (judgingRef.current) { + console.log("Judging already in progress, skipping duplicate call"); + return; + } + + judgingRef.current = true; + try { console.log("Starting judgment with messages:", messages); const { result } = await judgeDebate({ history: messages, userId: debateData.userId, }); + console.log("Raw judge result:", result); - + const jsonString = extractJSON(result); console.log("Extracted JSON string:", jsonString); - + let judgment: JudgmentData; try { judgment = JSON.parse(jsonString); } catch (parseError) { console.error("JSON parse error:", parseError, "Trying to fix JSON..."); - // Try to fix common JSON issues const fixedJson = jsonString - .replace(/'/g, '"') // Replace single quotes with double quotes - .replace(/(\w+):/g, '"$1":') // Add quotes to keys - .replace(/,\s*}/g, '}') // Remove trailing commas - .replace(/,\s*]/g, ']'); // Remove trailing commas in arrays - try { - judgment = JSON.parse(fixedJson); - } catch (e) { - throw new Error(`Failed to parse JSON: ${e}`); - } + .replace(/'/g, '"') + .replace(/(\w+):/g, '"$1":') + .replace(/,\s*}/g, '}') + .replace(/,\s*]/g, ']'); + + judgment = JSON.parse(fixedJson); } - + console.log("Parsed judgment:", judgment); setJudgmentData(judgment); setPopup({ show: false, message: "" }); setShowJudgment(true); + } catch (error) { console.error("Judging error:", error); - // Show error to user + setPopup({ show: true, - message: `Judgment error: ${error instanceof Error ? error.message : "Unknown error"}. Showing default results.`, + message: `Judgment error: ${ + error instanceof Error ? error.message : "Unknown error" + }. Showing default results.`, isJudging: false, }); - - // Set default judgment data + setJudgmentData({ opening_statement: { user: { score: 0, reason: "Error occurred during judgment" }, @@ -643,13 +651,18 @@ const DebateRoom: React.FC = () => { opponent_analysis: "", }, }); + setTimeout(() => { setPopup({ show: false, message: "" }); setShowJudgment(true); }, 3000); + + } finally { + judgingRef.current = false; } }; + const formatTime = (seconds: number) => { const timeStr = `${Math.floor(seconds / 60)}:${(seconds % 60) .toString() @@ -747,7 +760,10 @@ const DebateRoom: React.FC = () => { userStance={state.userStance} botStance={state.botStance} botDesc={bot.desc} - onClose={() => setShowJudgment(false)} + onClose={() => { + setShowJudgment(false); + navigate("/"); + }} /> )} diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index 7a33148..788bfe9 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -121,8 +121,11 @@ function Header() { return ( <> -
-
{getBreadcrumbs()}
+
+
+ {getBreadcrumbs()} +
+
@@ -239,7 +242,7 @@ function Header() {
+