Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/polyblitz/frontend/src/LeaderBoard.tsx

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

put this page in the pages folder

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect, useState } from "react";
import axios from "axios";
import type { User } from "@repo/polyblitz-types";

export function Leaderboard() {
const [users, setUsers] = useState<User[]>([]);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
axios
.get("http://localhost:4590/api/leaderboard/leaderboard")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the backend url is saved in a const in App.tsx. use it and add the leaderboard text.

.then((res) => setUsers(res.data.sortedUsers))
.catch((err) => setError(err.message));
}, []);

if (error) return <p>{error}</p>;

return (
Comment on lines +16 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should probably do this with ternary

<ol>
{users.map((user) => (
<li>
{user.name}: ${user.money}
</li>
))}
</ol>
);
}
Loading