forked from kossiitkgp/KWoC-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kossiitkgp#195 Issue:Project Stats Page
- Loading branch information
1 parent
377b406
commit 85d46c1
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string | null>(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 ( | ||
<div className="flex flex-col items-center pt-28"> | ||
<h1 className="font-display text-5xl md:text-7xl font-bold text-center"> | ||
Project Stats | ||
</h1> | ||
{error !== null ? ( | ||
<p className="text-center text-red-500">{error}</p> | ||
) : projectStats !== null ? ( | ||
<div className="max-w-7xl px-8 py-4"> | ||
<table className="min-w-full"> | ||
<thead> | ||
<tr> | ||
<th>Project Name</th> | ||
<th>Repository Link</th> | ||
<th>Commit Count</th> | ||
<th>Pull Count</th> | ||
{/* Add more columns as needed */} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{projectStats.projects.map((project) => ( | ||
<tr key={project.id}> | ||
<td>{project.name}</td> | ||
<td>{project.repo_link}</td> | ||
<td>{project.commit_count}</td> | ||
<td>{project.pull_count}</td> | ||
{/* Add more cells as needed */} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
) : ( | ||
null | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default ProjectStats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters