diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-11-05 15:52:09 -0800 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-11-05 15:52:09 -0800 |
| commit | 8052754a4bcc3d07208d11aad764d2bb3492166d (patch) | |
| tree | cd12af3d27ffa124bb3a64c29cbc44e3c2b8ce08 | |
| parent | 44606b2c510bb327982f60506fc0c968a51b6e80 (diff) | |
add profile page to navbar
| -rw-r--r-- | backend/src/routes/user.ts | 3 | ||||
| -rw-r--r-- | frontend/src/components/NavBar.tsx | 11 | ||||
| -rw-r--r-- | frontend/src/pages/Profile.tsx | 13 |
3 files changed, 20 insertions, 7 deletions
diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index 7e030fd..96a452e 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -31,7 +31,8 @@ export const handleMeRoute = async (req: express.Request, res: express.Response) FROM "Score" s INNER JOIN "Game" g ON g."internalName" = s."gameInternalName" WHERE s."userId" = ${parseInt(userId as string)} - ORDER BY s."gameInternalName", s."timestamp" DESC; + ORDER BY s."gameInternalName", s."timestamp" DESC + LIMIT 5; `; const scoreCountByGame: SafeGameCount[] = await prisma.$queryRaw` SELECT diff --git a/frontend/src/components/NavBar.tsx b/frontend/src/components/NavBar.tsx index 296ac49..6edfcde 100644 --- a/frontend/src/components/NavBar.tsx +++ b/frontend/src/components/NavBar.tsx @@ -22,6 +22,17 @@ export const NavBar = ({ currentPage, user, handleLogout }: { Home </Link> <Link + to="/profile" + className={`px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${ + currentPage === 'profile' + ? 'bg-violet-600 text-white shadow-lg shadow-violet-500/25' + : 'text-slate-300 hover:text-white hover:bg-slate-800/50' + }`} + onClick={() => setIsMobileMenuOpen(false)} + > + Profile + </Link> + <Link to="/import" className={`px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${ currentPage === 'import' diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 83aa701..8a78fcf 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx @@ -30,7 +30,7 @@ interface UserData { const Profile = () => { const { user, isLoading, logout } = useAuth(); - const targetUser = + let targetUser = new URLSearchParams(window.location.search).get("userId") || ""; // looking at profile of this user const navigate = useNavigate(); const [fetchingHeatmapData, setFetchingHeatmapData] = useState(true); @@ -101,14 +101,15 @@ const Profile = () => { } }, [targetUser]); - if (!targetUser) { - navigate("/"); - } - if (!user) { return <SessionExpiredPopup />; } + if (!targetUser) { + targetUser = user.id.toString(); + } + + if (isLoading || fetchingHeatmapData || fetchingUserData) { return <LoadingDisplay message="Loading Profile Page..." />; } @@ -129,7 +130,7 @@ const Profile = () => { return ( <div className="min-h-screen bg-slate-950"> - <NavBar user={user} handleLogout={handleLogout} currentPage="" /> + <NavBar user={user} handleLogout={handleLogout} currentPage="profile" /> {/* Main Content */} <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4 sm:py-8"> |
