diff --git a/src/App.tsx b/src/App.tsx index c91c90bf..765b0dc8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,7 @@ import PastProgramsPage from "./pages/PastProgramsPage"; import StudentDashboard from "./pages/StudentDashboard"; import RegistrationForm from "./pages/RegistrationForm"; import NotFoundPage from "./pages/404"; +import ProjectStats from "./pages/ProjectStat"; function App() { return ( @@ -61,6 +62,10 @@ function App() { path={ROUTER_PATHS.PASTPROGRAMS} element={} /> + } + /> } /> diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 40aaea15..e7ac0419 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -17,6 +17,7 @@ const LINKS = [ { name: "PROJECTS", link: ROUTER_PATHS.PROJECTS_LIST }, // { name: "TESTIMONIALS", link: ROUTER_PATHS.TESTIMONIALS }, { name: "FAQs", link: ROUTER_PATHS.FAQ }, + { name: "PROJECT STATS", link: ROUTER_PATHS.ALL_PROJECT_STATS }, ]; function BrandLogo() { diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx new file mode 100644 index 00000000..f7a5496c --- /dev/null +++ b/src/pages/ProjectStat.tsx @@ -0,0 +1,72 @@ +import { useEffect, useState } from "react"; +import { makeRequest } from "../util/backend"; +import { IEndpointTypes } from "../util/types"; +import { useAuthContext } from "../util/auth"; + +// ... (imports) + +function ProjectStats() { + const authContext = useAuthContext(); + const [projectStats, setProjectStats] = useState< + IEndpointTypes["stats/projects"]["response"] | null + >(null); + const [error, setError] = useState(null); + + useEffect(() => { + makeRequest("stats/projects", "get", null, authContext.jwt) + .then((response) => { + if (response.is_ok) { + setProjectStats(response.response); + } else { + setError("Error fetching project stats."); + console.log(response.response); + } + }) + .catch((e) => { + setError("Error fetching project stats."); + console.log(e); + }); + }, []); + + return ( +
+

+ Project Stats +

+ {error !== null ? ( +

{error}

+ ) : projectStats !== null ? ( +
+ + + + + + + + + + + + + + {projectStats.map((project) => ( + + + + + + + + + + ))} + +
Project NameRepository LinkCommit CountPull CountLines AddedLines RemovedLanguages Used
{project.name}{project.repo_link}{project.commit_count}{project.pull_count}{project.lines_added}{project.lines_removed}{project.languages_used.join(", ")}
+
+ ) : null} +
+ ); +} + +export default ProjectStats; diff --git a/src/util/types.ts b/src/util/types.ts index 8b9cd673..16cbc8c3 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -78,6 +78,18 @@ export interface IEndpointTypes { students: IStudentInfo[]; }; }; + "stats/projects": { + request: null; + response: { + name: string; + repo_link: string; + commit_count: number; + pull_count: number; + lines_added: number; + lines_removed: number; + languages_used: string[]; + }[]; + }; [route: `project/${number}`]: { request: null; response: IProject;