Skip to content

Commit

Permalink
added rankings page
Browse files Browse the repository at this point in the history
  • Loading branch information
lowtorola committed Jul 6, 2023
1 parent ae7f7f7 commit 1a848ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontend2/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "react-router-dom";
import { DEFAULT_EPISODE } from "./utils/constants";
import NotFound from "./views/NotFound";
import Rankings from "./views/Rankings";

const App: React.FC = () => {
const [episodeId, setEpisodeId] = useState(DEFAULT_EPISODE);
Expand All @@ -38,10 +39,11 @@ const router = createBrowserRouter([
element: <EpisodeLayout />,
children: [
// Pages that should always be visible
// TODO: /:episodeId/resources, /:episodeId/tournaments, /:episodeId/rankings, /:episodeId/queue
// TODO: /:episodeId/resources, /:episodeId/tournaments, /:episodeId/queue
{ path: "/:episodeId/home", element: <Home /> },
{ path: "/:episodeId/quickstart", element: <QuickStart /> },
{ path: "/:episodeId/*", element: <NotFound /> },
{ path: "/:episodeId/rankings", element: <Rankings /> },
// Pages that should only be visible when logged in
// TODO: /:episodeId/team, /:episodeId/submissions, /:episodeId/scrimmaging
{ path: "/account", element: <Account /> },
Expand Down
71 changes: 71 additions & 0 deletions frontend2/src/views/Rankings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useContext, useEffect, useState } from "react";
import { EpisodeContext } from "../contexts/EpisodeContext";
import { Api } from "../utils/api";
import BattlecodeTable from "../components/BattlecodeTable";
import { PaginatedTeamPublicList } from "../utils/types/model/PaginatedTeamPublicList";
import BattlecodeTableBottomElement from "../components/BattlecodeTableBottomElement";

const Rankings: React.FC = () => {
const episodeId = useContext(EpisodeContext);

const [page, setPage] = useState<number>(1);
const [searchQuery, setSearchQuery] = useState<string>("");

Check warning on line 12 in frontend2/src/views/Rankings.tsx

View workflow job for this annotation

GitHub Actions / Frontend linting / unit tests

'setSearchQuery' is assigned a value but never used
const [requireActiveSubmission, setRequireActiveSubmission] =

Check warning on line 13 in frontend2/src/views/Rankings.tsx

View workflow job for this annotation

GitHub Actions / Frontend linting / unit tests

'requireActiveSubmission' is assigned a value but never used

Check warning on line 13 in frontend2/src/views/Rankings.tsx

View workflow job for this annotation

GitHub Actions / Frontend linting / unit tests

'setRequireActiveSubmission' is assigned a value but never used
useState<boolean>(false);

const [data, setData] = useState<PaginatedTeamPublicList | undefined>(
undefined
);

const queryVars = {
episodeId: episodeId.episodeId,
searchQuery: searchQuery,

Check warning on line 22 in frontend2/src/views/Rankings.tsx

View workflow job for this annotation

GitHub Actions / Frontend linting / unit tests

Expected property shorthand
requireActiveSubmission: false,
page: page,

Check warning on line 24 in frontend2/src/views/Rankings.tsx

View workflow job for this annotation

GitHub Actions / Frontend linting / unit tests

Expected property shorthand
};

useEffect(() => {
Api.searchTeams(
queryVars.episodeId,
queryVars.searchQuery,
queryVars.requireActiveSubmission,
queryVars.page
).then((res) => setData(res));
}, [queryVars]);

if (!data) {
return <>Loading...</>;
}

return (
<>
<h1 className="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl dark:text-white">
Rankings
</h1>
<div style={{ height: 100 }} />
<BattlecodeTable
data={data.results ?? []}
bottomElement={
<BattlecodeTableBottomElement
totalCount={data.count ?? 0}
pageSize={10}
currentPage={page}
onPage={(page) => setPage(page)}
/>
}
columns={[
{
header: "Rating",
value: (team) => team.profile?.rating ?? 0,
},
{
header: "Team",
value: (team) => team.name,
},
]}
/>
</>
);
};

export default Rankings;

0 comments on commit 1a848ad

Please sign in to comment.