diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index 8d22a22..524ebf4 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -2,28 +2,27 @@ import { useEffect, useState } from "react"; import { FaBrain, FaChevronLeft, FaRobot } from "react-icons/fa"; import { RiLinkedinFill, RiLinkM, RiTwitterFill } from "react-icons/ri"; import { - SiC, - SiCplusplus, - SiCsharp, - SiGoland, - SiJavascript, - SiPhp, - SiPython, - SiReact, - SiRuby, - SiRust, - SiTypescript, + SiC, + SiCplusplus, + SiCsharp, + SiGoland, + SiJavascript, + SiPhp, + SiPython, + SiReact, + SiRuby, + SiRust, + SiTypescript, } from "react-icons/si"; import { DiJava } from "react-icons/di"; import OpenSaucedLogo from "../../assets/opensauced-logo.svg"; import { - getUserData, - getUserPRData, - getUserHighlightsData, + getUserData, + getUserPRData, + getUserHighlightsData, } from "../../utils/fetchOpenSaucedApiData"; 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"; @@ -32,215 +31,206 @@ import { optLogOut } from "../../utils/checkAuthentication"; import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../constants"; const interestIcon = { - python: , - java: , - javascript: , - typescript: , - csharp: , - cpp: , - c: , - php: , - ruby: , - react: , - ml: , - ai: , - golang: , - rust: , + python: , + java: , + javascript: , + typescript: , + csharp: , + cpp: , + c: , + php: , + ruby: , + react: , + ml: , + ai: , + golang: , + rust: , }; type InterestIconKeys = keyof typeof interestIcon; export const Profile = ({ username }: { username: string }) => { - const [user, setUser] = useState(null); - const [userPR, setUserPR] = useState(null); - const [userHighlights, setUserHighlights] = useState(null); - const [userPRVelocity, setUserPRVelocity] = useState(0); - - useEffect(() => { - const fetchUserData = async () => { - const [userData, userPRData, userHighlightsData] = - await Promise.all([ - getUserData(username), - getUserPRData(username), - getUserHighlightsData(username), - ]); - - setUser(userData); - setUserPR(userPRData); - setUserHighlights(userHighlightsData); - setUserPRVelocity(getUserPRVelocity(userPRData?.data || [])); - }; - - void fetchUserData(); - }, []); - - return ( -
-
-
-
- - - OpenSauced logo -
- - -
- -
-
- - User avatar - -

@{username}

-
- - {(user?.linkedin_url || user?.twitter_username) && ( -
- {user.linkedin_url && ( - - - - )} - - {user.twitter_username && ( - - - - )} -
- )} - - {user?.bio && {emojify(user.bio)}} - - {user?.blog && ( - - - - {user.blog} - - )} -
- -
-
-

Total Highlights

- -

- {userHighlights?.meta.itemCount} -

-
- -
-

PR Count

- -

- {userPR?.meta.itemCount} -

-
- -
-

Avg PRs Velocity

- -

- {getRelativeDays(userPRVelocity)} -

-
- -
-

Contributed Repos

- -

- {countUniqueRepos(userPR)} -

-
-
- -
-

- Current Interest -

- -
- {user?.interests.split(",").map((interest) => ( - - {interestIcon[interest as InterestIconKeys]} - - {interest} - - ))} -
-
-
+ const [user, setUser] = useState(null); + const [userPR, setUserPR] = useState(null); + const [userHighlights, setUserHighlights] = useState(null); + const [_, setUserPRVelocity] = useState(0); + + useEffect(() => { + const fetchUserData = async () => { + const [userData, userPRData, userHighlightsData] = await Promise.all([ + getUserData(username), + getUserPRData(username), + getUserHighlightsData(username), + ]); + + setUser(userData); + setUserPR(userPRData); + setUserHighlights(userHighlightsData); + setUserPRVelocity(getUserPRVelocity(userPRData?.data || [])); + }; + + void fetchUserData(); + }, []); + + return ( +
+
+
+
+ + + OpenSauced logo +
+ + +
+ +
+
+ + User avatar + +

@{username}

+
+ + {(user?.linkedin_url || user?.twitter_username) && ( +
+ {user.linkedin_url && ( + + + + )} + + {user.twitter_username && ( + + + + )} +
+ )} + + {user?.bio && {emojify(user.bio)}} + + {user?.blog && ( + + + + {user.blog} + + )} +
+ +
+
+

Total Highlights

+ +

+ {userHighlights?.meta.itemCount} +

-
- ); + +
+

PR Count (30 days)

+ +

{userPR?.meta.itemCount}

+
+ +
+

OSCR

+ + {user && ( +

{Math.ceil(user.oscr)}

+ )} +
+ +
+

Contributed Repos (30 days)

+ +

{countUniqueRepos(userPR)}

+
+
+ +
+

Current Interest

+ +
+ {user?.interests.split(",").map((interest) => ( + + {interestIcon[interest as InterestIconKeys]} + + {interest} + + ))} +
+
+ +
+
+ ); };