Skip to content

Commit

Permalink
feat: replace open issues count with highlights count (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgursar committed May 14, 2023
1 parent d49015d commit 0fb8149
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AiOutlineReload } from "react-icons/ai";
import { 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 } from "../utils/fetchOpenSaucedApiData";
import { getUserData, getUserPRData, getUserHighlightsData } from "../utils/fetchOpenSaucedApiData";
import { RouteContext } from "../App";
import { emojify } from "node-emoji";

Expand All @@ -32,13 +32,15 @@ export const Profile = () => {
const { page, setCurrentPage } = useContext(RouteContext);
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 [userHighlights, setUserHighlights] = useState<null | { meta: { itemCount: number } }>(null);

useEffect(() => {
const fetchUserData = async () => {
const [userData, userPRData] = await Promise.all([getUserData(page.props.userName), getUserPRData(page.props.userName)]);
const [userData, userPRData, userHighlightsData] = await Promise.all([getUserData(page.props.userName), getUserPRData(page.props.userName), getUserHighlightsData(page.props.userName)]);

setUser(userData);
setUserPR(userPRData);
setUserHighlights(userHighlightsData);
};

void fetchUserData();
Expand Down Expand Up @@ -142,15 +144,15 @@ export const Profile = () => {

<div className="grid grid-cols-2 text-white bg-osOrange -mx-4 mb-4 p-4 py-8">
<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>Open Issues</p>
<p>Total Highlights</p>

<p className="font-medium text-5xl">
{user?.open_issues}
{userHighlights?.meta.itemCount}
</p>
</div>

<div className="flex flex-col items-center justify-center p-2 text-xs">
<p>PRs Made</p>
<p>PR Count</p>

<p className="font-medium text-5xl">
{userPR?.meta.itemCount}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/fetchOpenSaucedApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export const getUserPRData = async (userName: string, forceRefresh: boolean = fa
})
.then(json => json);

export const getUserHighlightsData = async (userName: string, forceRefresh: boolean = false) => cachedFetch(`${OPEN_SAUCED_USERS_ENDPOINT}/${userName}/highlights`, {
expireInSeconds: 2 * 60 * 60,
forceRefresh,
headers: { Accept: "application/json" },
}).then(async resp => {
if (!resp?.ok) {
console.log("error getting user highlights info");
}
return resp?.json();
})
.then(json => json);

const getUserVotes = async (userToken: string, page: number = 1, limit: number = 1000, repos: any[] = []): Promise<any[]> => {
const response = await fetch(
`${OPEN_SAUCED_REPOS_ENDPOINT}/listUserVoted?page=${page}&limit=${limit}`,
Expand Down

0 comments on commit 0fb8149

Please sign in to comment.