Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Contributed Repos to profile page #181

Merged
merged 13 commits into from
Jun 14, 2023
9 changes: 6 additions & 3 deletions src/popup/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
diivi marked this conversation as resolved.
Show resolved Hide resolved
import { getUserPRVelocity } from "../../utils/getUserPRVelocity";
import { BiExit } from "react-icons/bi";
import Start from "./start";
Expand Down Expand Up @@ -35,7 +36,7 @@ type InterestIconKeys = keyof typeof interestIcon;

export const Profile = ({ username }: { username: string }) => {
const [user, setUser] = useState<null | { id: string, user_name: string, bio: string, created_at: string, linkedin_url: string, twitter_username: string, blog: string, interests: string, open_issues: number }>(null);
const [userPR, setUserPR] = useState<null | { meta: { itemCount: number } }>(null);
const [userPR, setUserPR] = useState<PRResponse | null>(null);
const [userHighlights, setUserHighlights] = useState<null | { meta: { itemCount: number } }>(null);
const [userPRVelocity, setUserPRVelocity] = useState<number>(0);

Expand Down Expand Up @@ -82,7 +83,7 @@ export const Profile = ({ username }: { username: string }) => {
}}
>
<BiExit />
Log Out
Log Out
</button>
</header>

Expand Down Expand Up @@ -178,7 +179,9 @@ export const Profile = ({ username }: { username: string }) => {
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>Contributed Repos</p>

<p className="font-medium text-5xl">-</p>
<p className="font-medium text-5xl">
{countUniqueRepos(userPR)}
</p>
</div>
</div>

Expand Down
19 changes: 19 additions & 0 deletions src/utils/getContributedRepos.ts
Original file line number Diff line number Diff line change
@@ -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;
};