From 0fb814901fd575d3f1434740f8f8140fc6ff1aae Mon Sep 17 00:00:00 2001 From: Ozgur Sar Date: Sun, 14 May 2023 18:27:19 +0300 Subject: [PATCH] feat: replace open issues count with highlights count (#76) --- src/pages/profile.tsx | 12 +++++++----- src/utils/fetchOpenSaucedApiData.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx index 453bebe3..49b07b3b 100644 --- a/src/pages/profile.tsx +++ b/src/pages/profile.tsx @@ -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"; @@ -32,13 +32,15 @@ export const Profile = () => { const { page, setCurrentPage } = useContext(RouteContext); const [user, setUser] = useState(null); const [userPR, setUserPR] = useState(null); + const [userHighlights, setUserHighlights] = useState(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(); @@ -142,15 +144,15 @@ export const Profile = () => {
-

Open Issues

+

Total Highlights

- {user?.open_issues} + {userHighlights?.meta.itemCount}

-

PRs Made

+

PR Count

{userPR?.meta.itemCount} diff --git a/src/utils/fetchOpenSaucedApiData.ts b/src/utils/fetchOpenSaucedApiData.ts index 78dfd14e..c1de589a 100644 --- a/src/utils/fetchOpenSaucedApiData.ts +++ b/src/utils/fetchOpenSaucedApiData.ts @@ -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 => { const response = await fetch( `${OPEN_SAUCED_REPOS_ENDPOINT}/listUserVoted?page=${page}&limit=${limit}`,