From 4901f7b322b87e27ed755be598c2975d6329f067 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 03:19:22 +0530 Subject: [PATCH] feat: Added Contributed Repos to profile page (#181) Co-authored-by: Brian Douglas Co-authored-by: Divyansh Singh --- src/popup/pages/profile.tsx | 9 ++++++--- src/utils/getContributedRepos.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/utils/getContributedRepos.ts diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index dc8b8dfc..2c0a80e7 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -8,6 +8,7 @@ import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/f import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; import { getRelativeDays } from "../../utils/dateUtils"; +import { countUniqueRepos, PRResponse } from "../../utils/getContributedRepos"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; @@ -35,7 +36,7 @@ type InterestIconKeys = keyof typeof interestIcon; export const Profile = ({ username }: { username: string }) => { const [user, setUser] = useState(null); - const [userPR, setUserPR] = useState(null); + const [userPR, setUserPR] = useState(null); const [userHighlights, setUserHighlights] = useState(null); const [userPRVelocity, setUserPRVelocity] = useState(0); @@ -82,7 +83,7 @@ export const Profile = ({ username }: { username: string }) => { }} > - Log Out + Log Out @@ -178,7 +179,9 @@ export const Profile = ({ username }: { username: string }) => {

Contributed Repos

-

-

+

+ {countUniqueRepos(userPR)} +

diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts new file mode 100644 index 00000000..48913ca6 --- /dev/null +++ b/src/utils/getContributedRepos.ts @@ -0,0 +1,19 @@ +export interface PRResponse { + data: { + full_name: string; + }[] + meta: { + itemCount: number; + }; +} + +export const countUniqueRepos = (response: PRResponse | null):number => { + if (!response?.data) { + return 0; + } + + const { data } = response; + const uniqueRepos = new Set(data.map(obj => obj.full_name)); + + return uniqueRepos.size; +};