From 1a848ad4ba5a53787b8c84e5cc74f2ba9f76ea89 Mon Sep 17 00:00:00 2001 From: Lowell Torola Date: Wed, 5 Jul 2023 22:54:32 -0400 Subject: [PATCH] added rankings page --- frontend2/src/App.tsx | 4 +- frontend2/src/views/Rankings.tsx | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 frontend2/src/views/Rankings.tsx diff --git a/frontend2/src/App.tsx b/frontend2/src/App.tsx index 3563aeec1..cbdbf57f5 100644 --- a/frontend2/src/App.tsx +++ b/frontend2/src/App.tsx @@ -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); @@ -38,10 +39,11 @@ const router = createBrowserRouter([ element: , 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: }, { path: "/:episodeId/quickstart", element: }, { path: "/:episodeId/*", element: }, + { path: "/:episodeId/rankings", element: }, // Pages that should only be visible when logged in // TODO: /:episodeId/team, /:episodeId/submissions, /:episodeId/scrimmaging { path: "/account", element: }, diff --git a/frontend2/src/views/Rankings.tsx b/frontend2/src/views/Rankings.tsx new file mode 100644 index 000000000..57d1b6dcb --- /dev/null +++ b/frontend2/src/views/Rankings.tsx @@ -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(1); + const [searchQuery, setSearchQuery] = useState(""); + const [requireActiveSubmission, setRequireActiveSubmission] = + useState(false); + + const [data, setData] = useState( + undefined + ); + + const queryVars = { + episodeId: episodeId.episodeId, + searchQuery: searchQuery, + requireActiveSubmission: false, + page: page, + }; + + useEffect(() => { + Api.searchTeams( + queryVars.episodeId, + queryVars.searchQuery, + queryVars.requireActiveSubmission, + queryVars.page + ).then((res) => setData(res)); + }, [queryVars]); + + if (!data) { + return <>Loading...; + } + + return ( + <> +

+ Rankings +

+
+ setPage(page)} + /> + } + columns={[ + { + header: "Rating", + value: (team) => team.profile?.rating ?? 0, + }, + { + header: "Team", + value: (team) => team.name, + }, + ]} + /> + + ); +}; + +export default Rankings;