From 0089b3e8ae396ff03eb737463ab38fb6e0670704 Mon Sep 17 00:00:00 2001 From: "[anudeep avula]" <[anudeepavula009@gmail.com]> Date: Fri, 10 Jan 2025 11:45:11 +0530 Subject: [PATCH 1/2] Feat:Feature to create a shareable link showcasing user open PRs --- index.html | 2 +- src/Routes/Router.tsx | 2 + src/components/PRlist.tsx | 118 ++++++++++++++++++++++++++++++++++++++ src/pages/Home/Home.tsx | 14 +++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/components/PRlist.tsx diff --git a/index.html b/index.html index e4b78ea..f275256 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - Vite + React + TS + GitHub Tracker
diff --git a/src/Routes/Router.tsx b/src/Routes/Router.tsx index 91c2582..5daf98f 100644 --- a/src/Routes/Router.tsx +++ b/src/Routes/Router.tsx @@ -6,12 +6,14 @@ import Contact from "../pages/Contact/Contact"; // Import the Contact component import Contributors from "../pages/Contributors/Contributors"; import Login from "../pages/Auth/Login"; import Signup from "../pages/Auth/Signup"; +import PRlist from "../components/PRlist"; const Router = () => { return ( {/* Redirect from root (/) to the home page */} } /> + } /> } /> } /> } /> diff --git a/src/components/PRlist.tsx b/src/components/PRlist.tsx new file mode 100644 index 0000000..2e06eb8 --- /dev/null +++ b/src/components/PRlist.tsx @@ -0,0 +1,118 @@ +import { useEffect, useState } from "react"; +import { useParams } from "react-router-dom"; +import { + Container, + Paper, + Box, + CircularProgress, + Alert, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Link, +} from "@mui/material"; + + +interface PR { + id: number; + title: string; + html_url: string; + repository_url: string; + state: string; + created_at: string; +} + + +const PRlist = () => { + const { gitusername } = useParams<{ gitusername: string }>(); + const [prs, setPrs] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(""); + + useEffect(() => { + if (gitusername) { + const fetchPRs = async () => { + setLoading(true); + setError(""); + try { + // Fetch PRs from GitHub API (public repos only) + const response = await fetch(`https://api.github.com/search/issues?q=type:pr+author:${gitusername}+state:open`); + const data = await response.json(); + setPrs(data.items || []); + } catch (err) { + console.error("Error fetching PRs:", err); + setError("Error fetching pull requests."); + } finally { + setLoading(false); + } + }; + + fetchPRs(); + } + }, [gitusername]); + + const formatDate = (dateString: string): string => { + return new Date(dateString).toLocaleDateString(); + }; + + return ( + + +

{gitusername && `You are viewing ${gitusername}'s Open Pull Requests`}

+ {error && {error}} + + {loading ? ( + + + + ) : ( + + + + + Title + Repository + State + Created + + + + {prs.length > 0 ? ( + prs.map((pr) => ( + + + + {pr.title} + + + + {pr.repository_url.replace("https://api.github.com/repos/", "")} + + + {pr.state} + + + {formatDate(pr.created_at)} + + + )) + ) : ( + + + No open pull requests found for {gitusername}. + + + )} + +
+
+ )} +
+
+ ); +}; + +export default PRlist; diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index cab0b7d..9735571 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -82,6 +82,12 @@ const Home: React.FC = () => { return new Date(dateString).toLocaleDateString(); }; + // generates the shareable link + const generateSharableLink = () => { + const link = `${window.location.origin}/prs/${username}`; + window.navigator.clipboard.writeText(link); + }; + // Filter data based on selected criteria const filterData = ( data: GitHubItem[], @@ -214,6 +220,14 @@ const Home: React.FC = () => { + State