Skip to content

Commit

Permalink
Instead of username, camparing with id's in highlight part
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetDOD committed Jun 8, 2024
1 parent ba6bc24 commit 8cbfdfa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
1 change: 1 addition & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import LeaderBoard from "./pages/LeaderBoard";
// axios.defaults.baseURL = "http://localhost:3001/";

function App() {

return (
<BrowserRouter>
<RecoilRoot>
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/LeaderBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ILeaderboardUser } from '../types';
import { GiTrophyCup } from "react-icons/gi";
import { useRecoilValue } from 'recoil';
import { userState } from '../store/atoms/auth';
import { Navigate } from 'react-router-dom';

const LeaderBoard = () => {
const [loading, setLoading] = useState(true);
Expand All @@ -26,6 +27,10 @@ const LeaderBoard = () => {
fetchLeaderboard();
}, []);

if (!currentUser) {
return <Navigate to='/app' />
}

return (
<div className="p-3 mb-10">
<h2 className="text-3xl font-bold text-center mb-8 text-gray-50">Leaderboard 🥳</h2>
Expand All @@ -49,7 +54,7 @@ const LeaderBoard = () => {
{leaderboard.map((user, index) => (
<tr
key={user.userId}
className={`text-center text-gray-50 border-b-2 border-sky-900 font-semibold ${currentUser && user.username === currentUser.username ? ' bg-sky-500' : ''}`}
className={`text-center text-gray-50 border-b-2 border-sky-900 font-semibold ${currentUser && user.userId === currentUser.id ? ' bg-sky-500' : ''}`}
>
<td className='px-6 py-4 '>
{(index === 0 || index === 1 || index === 2) ? (
Expand All @@ -66,7 +71,7 @@ const LeaderBoard = () => {
</div>
</td>
<td className='px-6 py-4 '>
<div className={`text-sm text-gray-50 ${currentUser && user.username === currentUser.username ? 'font-bold' : ''}`}>@{user.username}</div>
<div className={`text-sm text-gray-50 ${currentUser && user.userId === currentUser.id ? 'font-bold' : ''}`}>@{user.username}</div>
</td>
<td className='px-6 py-4 '>
<div className="text-sm text-gray-50">{user.postCount}</div>
Expand Down

0 comments on commit 8cbfdfa

Please sign in to comment.