Skip to content

Commit 004c415

Browse files
committed
Fix bug where navigation by other means cause the navbar to not get updated
1 parent 64e4aec commit 004c415

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

frontend/src/app/components/home/WelcomeComponent.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import { Card, CardTitle, CardHeader, CardContent } from "@/components/ui/card";
44
import { Button } from "@/components/ui/button";
55
import { useUser } from "@/contexts/UserContext";
6+
import { useRouter } from "next/navigation";
67

78
export default function WelcomePage() {
89
const { user } = useUser();
10+
const router = useRouter();
911

10-
function directToHome() {
11-
window.location.href = "/match";
12+
function directToMatch() {
13+
router.push("/match");
1214
}
1315

1416
return (
@@ -24,7 +26,7 @@ export default function WelcomePage() {
2426
<CardContent>
2527
<Button
2628
className="w-30 bg-white border-black text-black border-2 border-black"
27-
onClick={() => directToHome()}
29+
onClick={() => directToMatch()}
2830
>
2931
Start
3032
</Button>

frontend/src/app/components/layout/Navbar.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* AI Assistance Disclosure:
3-
* Tool: GitHub Copilot (model: Claude 3.5 Sonnet), date: 2025-09-15
3+
* Tool: GitHub Copilot (model: Claude Sonnet 4), date: 2025-09-15
44
* Purpose: To create a reusable navigation bar component for the PeerPrep application.
55
* Author Review: I validated correctness, security, and performance of the code.
66
* I modified the styling to match the application's theme.
@@ -9,7 +9,7 @@
99
"use client";
1010

1111
import Link from "next/link";
12-
import { useState } from "react";
12+
import { usePathname } from "next/navigation";
1313
import { useRouter } from "next/navigation";
1414
import { Button } from "@/components/ui/button";
1515
import { User, LogOut, ChevronDown } from "lucide-react";
@@ -26,7 +26,7 @@ import {
2626
} from "@/components/ui/dropdown-menu";
2727

2828
export default function Navbar() {
29-
const [activeTab, setActiveTab] = useState("Dashboard");
29+
const pathname = usePathname();
3030
const { user, setUser } = useUser();
3131
const router = useRouter();
3232

@@ -75,9 +75,8 @@ export default function Navbar() {
7575
<Link
7676
key={item.name}
7777
href={item.href}
78-
onClick={() => setActiveTab(item.name)}
7978
className={`px-3 py-2 text-sm font-medium transition-colors ${
80-
activeTab === item.name
79+
pathname.startsWith(item.href)
8180
? "text-blue-600 border-b-2 border-blue-600"
8281
: "text-gray-600 hover:text-blue-600"
8382
}`}

0 commit comments

Comments
 (0)