From 85d46c1d9c15a81540f3a651f6c288f76f6a079a Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 09:57:14 +0530 Subject: [PATCH 1/8] #195 Issue:Project Stats Page --- src/App.tsx | 5 +++ src/components/Navbar.tsx | 1 + src/pages/ProjectStat.tsx | 76 +++++++++++++++++++++++++++++++++++++++ src/util/types.ts | 10 ++++++ 4 files changed, 92 insertions(+) create mode 100644 src/pages/ProjectStat.tsx 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..c1ab0a29 --- /dev/null +++ b/src/pages/ProjectStat.tsx @@ -0,0 +1,76 @@ +import { useEffect, useState } from "react"; +import { useParams } from "react-router-dom"; // Import useParams for accessing route parameters +import { makeRequest } from "../util/backend"; +import { useAuthContext } from "../util/auth"; +import { IEndpointTypes } from "../util/types"; +//import { Console } from "console"; + +function ProjectStats() { + console.log("abcd") + const authContext = useAuthContext(); + const [projectStats, setProjectStats] = useState< + IEndpointTypes["stats/projects"]["response"] | null + >(null); + const [error, setError] = useState(null); + + // Access the project ID from the route parameters + const { } = useParams(); + + useEffect(() => { + // Make a request to the specific project stats endpoint + makeRequest("stats/projects", "get", null, authContext.jwt) + .then((response) => { + console.log(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 ? ( +
+ + + + + + + + {/* Add more columns as needed */} + + + + {projectStats.projects.map((project) => ( + + + + + + {/* Add more cells as needed */} + + ))} + +
Project NameRepository LinkCommit CountPull Count
{project.name}{project.repo_link}{project.commit_count}{project.pull_count}
+
+ ) : ( + null + )} +
+ ); +} + +export default ProjectStats; diff --git a/src/util/types.ts b/src/util/types.ts index 8b9cd673..ee4ed2b9 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -78,6 +78,16 @@ export interface IEndpointTypes { students: IStudentInfo[]; }; }; + "stats/projects": { + request: null; + response: { + name: string; + username: string; + email: string; + projects: IProjectDashboardInfo[]; + students: IStudentInfo[]; + }; + }; [route: `project/${number}`]: { request: null; response: IProject; From 15885703f3da5fb165a3ecba6eb55db660ed37c1 Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 15:02:47 +0530 Subject: [PATCH 2/8] #195 again --- src/pages/ProjectStat.tsx | 23 ++++++++++------------- src/util/types.ts | 9 +++++---- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index c1ab0a29..1aa9a55e 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -1,26 +1,21 @@ import { useEffect, useState } from "react"; -import { useParams } from "react-router-dom"; // Import useParams for accessing route parameters -import { makeRequest } from "../util/backend"; -import { useAuthContext } from "../util/auth"; -import { IEndpointTypes } from "../util/types"; -//import { Console } from "console"; + + + function ProjectStats() { - console.log("abcd") + const authContext = useAuthContext(); const [projectStats, setProjectStats] = useState< IEndpointTypes["stats/projects"]["response"] | null >(null); - const [error, setError] = useState(null); - - // Access the project ID from the route parameters - const { } = useParams(); + useEffect(() => { // Make a request to the specific project stats endpoint makeRequest("stats/projects", "get", null, authContext.jwt) .then((response) => { - console.log(response) + if (response.is_ok) { setProjectStats(response.response); } else { @@ -50,7 +45,8 @@ function ProjectStats() { Repository Link Commit Count Pull Count - {/* Add more columns as needed */} + Lines Added + Lines Removed @@ -60,7 +56,8 @@ function ProjectStats() { {project.repo_link} {project.commit_count} {project.pull_count} - {/* Add more cells as needed */} + {project.lines_added} + {project.lines_removed} ))} diff --git a/src/util/types.ts b/src/util/types.ts index ee4ed2b9..2f463ace 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -82,10 +82,11 @@ export interface IEndpointTypes { request: null; response: { name: string; - username: string; - email: string; - projects: IProjectDashboardInfo[]; - students: IStudentInfo[]; + repo_link: string; + commit_count: uint; + pull_count: uint; + lines_added: uint; + lines_removed: uint; }; }; [route: `project/${number}`]: { From ec476093f4adac3ef4b6584c0acc0b78bd234deb Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 15:24:51 +0530 Subject: [PATCH 3/8] Update ProjectStat.tsx --- src/pages/ProjectStat.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index 1aa9a55e..61da5138 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -1,15 +1,18 @@ import { useEffect, useState } from "react"; - - - - +import { makeRequest } from "../util/backend"; +import { IEndpointTypes } from "../util/types"; +import { useAuthContext } from "../util/auth"; +import { useParams } from "react-router-dom"; function ProjectStats() { const authContext = useAuthContext(); const [projectStats, setProjectStats] = useState< IEndpointTypes["stats/projects"]["response"] | null >(null); - + const [error, setError] = useState(null); + + // Access the project ID from the route parameters + const { } = useParams(); useEffect(() => { // Make a request to the specific project stats endpoint @@ -47,6 +50,7 @@ function ProjectStats() { Pull Count Lines Added Lines Removed + Languages Used @@ -58,6 +62,7 @@ function ProjectStats() { {project.pull_count} {project.lines_added} {project.lines_removed} + {project.languages_used.join(", ")} ))} From 219f9363ab8d91bb97e57bc349860d086a9cb046 Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 15:30:19 +0530 Subject: [PATCH 4/8] Update ProjectStat.tsx --- src/pages/ProjectStat.tsx | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index 61da5138..6ab628fd 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -2,17 +2,13 @@ import { useEffect, useState } from "react"; import { makeRequest } from "../util/backend"; import { IEndpointTypes } from "../util/types"; import { useAuthContext } from "../util/auth"; -import { useParams } from "react-router-dom"; function ProjectStats() { const authContext = useAuthContext(); const [projectStats, setProjectStats] = useState< IEndpointTypes["stats/projects"]["response"] | null >(null); - const [error, setError] = useState(null); - - // Access the project ID from the route parameters - const { } = useParams(); + ; useEffect(() => { // Make a request to the specific project stats endpoint @@ -21,14 +17,8 @@ function ProjectStats() { 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); + } + }); }, []); @@ -37,8 +27,8 @@ function ProjectStats() {

Project Stats

- {error !== null ? ( -

{error}

+ ( +

) : projectStats !== null ? (
From 4aebed9b37f8ab8d7d85f8dc312347a77b84a88e Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 15:33:49 +0530 Subject: [PATCH 5/8] Update ProjectStat.tsx --- src/pages/ProjectStat.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index 6ab628fd..44d385b7 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -2,13 +2,15 @@ import { useEffect, useState } from "react"; import { makeRequest } from "../util/backend"; import { IEndpointTypes } from "../util/types"; import { useAuthContext } from "../util/auth"; + + function ProjectStats() { const authContext = useAuthContext(); const [projectStats, setProjectStats] = useState< IEndpointTypes["stats/projects"]["response"] | null >(null); - ; + const [error, setError] = useState(null); useEffect(() => { // Make a request to the specific project stats endpoint @@ -17,8 +19,14 @@ function ProjectStats() { 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); }); }, []); @@ -27,8 +35,8 @@ function ProjectStats() {

Project Stats

- ( -

+ {error !== null ? ( +

{error}

) : projectStats !== null ? (
@@ -40,7 +48,7 @@ function ProjectStats() { - + From e94b2b71a5f85ed050f521a3cba9df879544334c Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Sat, 6 Jan 2024 18:31:30 +0530 Subject: [PATCH 6/8] Update ProjectStat.tsx --- src/pages/ProjectStat.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index 44d385b7..4a7b727a 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -3,9 +3,7 @@ import { makeRequest } from "../util/backend"; import { IEndpointTypes } from "../util/types"; import { useAuthContext } from "../util/auth"; - function ProjectStats() { - const authContext = useAuthContext(); const [projectStats, setProjectStats] = useState< IEndpointTypes["stats/projects"]["response"] | null @@ -13,10 +11,8 @@ function ProjectStats() { const [error, setError] = useState(null); useEffect(() => { - // Make a request to the specific project stats endpoint makeRequest("stats/projects", "get", null, authContext.jwt) .then((response) => { - if (response.is_ok) { setProjectStats(response.response); } else { @@ -48,11 +44,11 @@ function ProjectStats() { - + - {projectStats.projects.map((project) => ( + {projectStats.map((project) => ( @@ -66,9 +62,7 @@ function ProjectStats() {
Pull Count Lines Added Lines RemovedLanguages UsedLanguage Used
Pull Count Lines Added Lines RemovedLanguage UsedLanguages Used
{project.name} {project.repo_link}
- ) : ( - null - )} + ) : null} ); } From 6df33a4a054ee6b06fed57582f40a19d3982d39f Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Mon, 8 Jan 2024 22:43:53 +0530 Subject: [PATCH 7/8] Update types.ts --- src/util/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/types.ts b/src/util/types.ts index 2f463ace..4ca86645 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -83,10 +83,10 @@ export interface IEndpointTypes { response: { name: string; repo_link: string; - commit_count: uint; - pull_count: uint; - lines_added: uint; - lines_removed: uint; + commit_count: number; + pull_count: number; + lines_added: number; + lines_removed: number; }; }; [route: `project/${number}`]: { From 6e6ef98f72fc5e318f8a0e74b808ac19747dfdf5 Mon Sep 17 00:00:00 2001 From: Pranjal Singh Date: Mon, 8 Jan 2024 22:56:39 +0530 Subject: [PATCH 8/8] updated --- src/pages/ProjectStat.tsx | 4 +++- src/util/types.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/ProjectStat.tsx b/src/pages/ProjectStat.tsx index 4a7b727a..f7a5496c 100644 --- a/src/pages/ProjectStat.tsx +++ b/src/pages/ProjectStat.tsx @@ -3,6 +3,8 @@ 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< @@ -49,7 +51,7 @@ function ProjectStats() { {projectStats.map((project) => ( - + {project.name} {project.repo_link} {project.commit_count} diff --git a/src/util/types.ts b/src/util/types.ts index 4ca86645..16cbc8c3 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -87,7 +87,8 @@ export interface IEndpointTypes { pull_count: number; lines_added: number; lines_removed: number; - }; + languages_used: string[]; + }[]; }; [route: `project/${number}`]: { request: null;