Skip to content

Fix duplicate Coach routes and improve routing structure#263

Open
Abhishek2005-ard wants to merge 9 commits intoAOSSIE-Org:mainfrom
Abhishek2005-ard:fix/duplicate-coach-routes
Open

Fix duplicate Coach routes and improve routing structure#263
Abhishek2005-ard wants to merge 9 commits intoAOSSIE-Org:mainfrom
Abhishek2005-ard:fix/duplicate-coach-routes

Conversation

@Abhishek2005-ard
Copy link
Contributor

@Abhishek2005-ard Abhishek2005-ard commented Jan 22, 2026

What does this PR do?
This PR resolves duplicate and inconsistent route definitions related to the Coach feature in App.jsx.

Problem

  • Duplicate /coach and coach/strengthen-argument routes were defined multiple times
  • Mixed absolute and relative paths inside nested routes
  • An orphan route without a path prop
  • Reduced readability and maintainability of routing configuration

Solution

  • Removed duplicate Coach route definitions
  • Refactored Coach routes using nested routing
  • Converted absolute paths to relative paths under Layout
  • Removed invalid route without a path
  • Grouped Coach-related routes for better scalability

Result

  • Clean, DRY, and predictable routing
  • Improved maintainability
  • No routing ambiguity

Screenshots / Testing

  • Verified navigation to /coach
  • Verified navigation to /coach/strengthen-argument
  • Verified navigation to /coach/pros-cons

Related Issue
Fixes: Duplicate Routes in App.jsx Causing Redundant Routing Definitions

close #261

Summary by CodeRabbit

  • Refactor

    • Reorganized routing into clear public vs. protected sections and added a catch-all redirect for unknown paths.
  • Bug Fixes

    • Prevented duplicate judgment submissions and improved judgment error handling and messaging.
    • Matchmaking UI reliably resets on page refresh.
  • New Features

    • Closing judgment results now returns users to home.
    • Judgment popup can display bot descriptions.
  • Style

    • Updated header/nav theming and select menu styling; added high-contrast support.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Reorganized app routing into explicit public vs protected nesting with a top-level catch-all redirect; added a re-entrancy guard and navigation flow in DebateRoom; passed botDesc into JudgmentPopup; reset Matchmaking UI state on mount; updated header/select styling and added high-contrast CSS variables.

Changes

Cohort / File(s) Summary
Routing Reorganization
frontend/src/App.tsx
Consolidated routes into public vs protected structure, removed duplicate coach route declarations, nested coach child routes under CoachPage, moved debate routes outside main layout, and added a catch-all path="*" redirect to /.
Debate logic & navigation
frontend/src/Pages/DebateRoom.tsx
Added judgingRef re-entrancy guard around judgeDebateResult, managed judging state with finally-release, refactored JSON parse/error handling, and navigate to / when closing JudgmentPopup.
Judgment UI
frontend/src/components/JudgementPopup.tsx
Destructures new botDesc prop to derive player2 description; no other behavior changes.
Matchmaking UI state
frontend/src/components/Matchmaking.tsx
On mount, resets isInPool and waitTime to ensure matchmaking UI resets on refresh.
Header / Theming
frontend/src/components/Header.tsx, frontend/src/index.css
Replaced hardcoded color classes with semantic tokens (bg-background, text-foreground, muted-foreground, border-border), adjusted drawer/header colors and hover states, and added .high-contrast CSS variables.
Select styling
frontend/src/components/ui/select.tsx
Updated SelectItem class composition: removed some focus classes, added data-[highlighted] and high-contrast variants, wrapped children in SelectPrimitive.ItemText; disabled handling preserved.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant DebateRoom
  participant Server
  participant JudgmentPopup
  participant Router

  User->>DebateRoom: trigger judge action
  DebateRoom->>DebateRoom: check judgingRef (prevent re-entrancy)
  DebateRoom->>Server: POST judgeDebateResult
  Server-->>DebateRoom: judgment result / error
  DebateRoom->>JudgmentPopup: open with judgment data (or default on error)
  User->>JudgmentPopup: close popup
  JudgmentPopup->>Router: navigate to "/"
  Router-->>User: redirected to root
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • bhavik-mangla

Poem

🐰 Routes hop tidy, no duplicates to spar,
A guard stands watch where judgments are,
Tokens shimmer, contrast bright and true,
Matchmaking wakes refreshed and new,
Hop, test, merge — carrots for you! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several changes appear unrelated to the core objective: Header theming updates, JudgmentPopup botDesc prop, Matchmaking state reset, SelectItem styling, and CSS high-contrast class are outside scope. Review and separate out-of-scope changes (Header styling, JudgmentPopup, Matchmaking, SelectItem, index.css) into dedicated PRs focused on routing only.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing duplicate coach routes and improving the routing structure, which aligns with the primary objective of the PR.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #261: removed duplicate route entries, established clearer nested routing under Layout, and improved routing structure and maintainability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/components/JudgementPopup.tsx (1)

94-107: Hardcoded localhost URLs will break in production.

The coachSkills array contains hardcoded http://localhost:5173 URLs. These won't work in deployed environments.

🐛 Suggested fix: Use relative paths
 const coachSkills: CoachSkill[] = [
   {
     title: 'Strengthen Argument',
     description:
       'Master the art of crafting compelling, persuasive arguments that win debates.',
-    url: 'http://localhost:5173/coach/strengthen-argument',
+    url: '/coach/strengthen-argument',
   },
   {
     title: 'Pros and Cons Challenge',
     description:
       'Test your critical thinking by crafting up to 5 pros and cons for engaging debate topics.',
-    url: 'http://localhost:5173/coach/pros-cons',
+    url: '/coach/pros-cons',
   },
 ];
🤖 Fix all issues with AI agents
In `@frontend/src/Pages/DebateRoom.tsx`:
- Around line 10-14: The hooks useRef and useNavigate are being called at module
scope (judgingRef and navigate) which violates React's Rules of Hooks; move the
calls inside the DebateRoom component so they are invoked during rendering:
remove the module-level declarations of judgingRef and navigate and create const
judgingRef = useRef(false) and const navigate = useNavigate() inside the
DebateRoom function (use appropriate typing if needed) and update any references
to those symbols to use the local variables.
🧹 Nitpick comments (2)
frontend/src/index.css (1)

88-91: Consider moving .high-contrast inside @layer base for consistency.

The .dark and .contrast theme classes are defined inside @layer base (lines 34-86), but .high-contrast is defined outside. This inconsistency may cause specificity issues since Tailwind's layer ordering affects cascade priority.

♻️ Suggested fix
   .contrast {
     /* ... existing contrast vars ... */
   }
+
+  .high-contrast {
+    --hc-hover-bg: 48 100% 50%;      
+    --hc-hover-text: 0 0% 0%;       
+  }
 }
-.high-contrast {
-  --hc-hover-bg: 48 100% 50%;      
-  --hc-hover-text: 0 0% 0%;       
-}
 
 `@layer` base {
frontend/src/components/Matchmaking.tsx (1)

38-44: Redundant effect: state is already initialized to these values.

This useEffect resets isInPool to false and waitTime to 0, but useState already initializes them to these exact values on lines 32-33. The effect is unnecessary unless there's a specific scenario (like HMR state persistence) that requires explicit reset.

Additionally, the indentation appears incorrect—the effect body is indented with extra spaces.

♻️ Consider removing this redundant effect
-    // Reset matchmaking UI state on page refresh
-    useEffect(() => {
-      setIsInPool(false);
-      setWaitTime(0);
-    }, []);
-
-

If there's a specific reason for this reset (e.g., state rehydration from a persistence layer), please add a comment explaining the use case.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/Pages/DebateRoom.tsx`:
- Line 10: Remove the duplicate import of useNavigate (the second import
statement that re-imports useNavigate) to resolve the noRedeclare error; keep
the single existing import where useNavigate is already imported (ensure the
remaining import that references useNavigate is the only one in DebateRoom.tsx
and remove the redundant import line).
♻️ Duplicate comments (1)
frontend/src/Pages/DebateRoom.tsx (1)

13-14: Move hooks into DebateRoom to satisfy Rules of Hooks.

useRef/useNavigate at module scope will throw at runtime; navigate is already declared inside the component.

🐛 Proposed fix
-const judgingRef = useRef(false);
-const navigate = useNavigate();
 
 const DebateRoom: React.FC = () => {
   const location = useLocation();
   const navigate = useNavigate();
@@
   const recognitionRef = useRef<SpeechRecognition | null>(null);
+  const judgingRef = useRef(false);
#!/bin/bash
# Verify hooks are not declared at module scope
rg -n "useRef\\(|useNavigate\\(" frontend/src/Pages/DebateRoom.tsx | head -n 20
🧹 Nitpick comments (2)
frontend/src/components/Header.tsx (2)

130-193: Inconsistent theming: popovers still use hardcoded gray colors.

The header, drawer, and NavItem were updated to use semantic tokens (text-foreground, bg-muted, etc.), but the notification popover still uses hardcoded colors like text-gray-600, border-gray-100, text-gray-900, and bg-gray-50. This will cause visual inconsistency if dark mode or custom themes are used.

Consider updating these to semantic tokens as well (e.g., text-muted-foreground, border-border, text-foreground, bg-muted).


195-241: Same theming inconsistency in user popover.

The user profile popover also uses hardcoded gray-* colors throughout. Apply the same semantic token updates here for consistency with the header and drawer styling changes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/Pages/DebateRoom.tsx`:
- Around line 220-223: There is a duplicate declaration of the navigate hook:
remove the redundant `const navigate = useNavigate();` so only one `navigate`
variable is defined in DebateRoom (keep the existing `useNavigate()` usage and
delete the second occurrence), ensuring the single `navigate` binding is used
throughout and React hooks rules are preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Duplicate Routes in App.jsx Causing Redundant Routing Definitions

1 participant