diff --git a/package.json b/package.json index 0959253..6d4d9ec 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,10 @@ "devDependencies": { "@eslint/js": "^9.13.0", "@types/node": "^22.10.1", - "@types/react": "^18.3.12", - "@types/react-dom": "^18.3.1", + "@types/react": "^18.3.23", + "@types/react-dom": "^18.3.7", "@types/react-redux": "^7.1.34", + "@types/react-router-dom": "^5.3.3", "@vitejs/plugin-react-swc": "^3.5.0", "autoprefixer": "^10.4.20", "eslint": "^9.13.0", diff --git a/src/pages/UserProfile/UserProfile.tsx b/src/pages/UserProfile/UserProfile.tsx index abf9791..8a7d993 100644 --- a/src/pages/UserProfile/UserProfile.tsx +++ b/src/pages/UserProfile/UserProfile.tsx @@ -1,5 +1,6 @@ import { useParams } from "react-router-dom"; import { useEffect, useState } from "react"; +import toast from "react-hot-toast"; type PR = { title: string; @@ -17,41 +18,69 @@ export default function UserProfile() { async function fetchData() { if (!username) return; - const userRes = await fetch(`https://api.github.com/users/${username}`); - const userData = await userRes.json(); - setProfile(userData); + try { + const userRes = await fetch(`https://api.github.com/users/${username}`); + const userData = await userRes.json(); + setProfile(userData); - const prsRes = await fetch(`https://api.github.com/search/issues?q=author:${username}+type:pr`); - const prsData = await prsRes.json(); - setPRs(prsData.items); - setLoading(false); + const prsRes = await fetch(`https://api.github.com/search/issues?q=author:${username}+type:pr`); + const prsData = await prsRes.json(); + setPRs(prsData.items); + } catch (error) { + toast.error("Failed to fetch user data."); + } finally { + setLoading(false); + } } fetchData(); }, [username]); + const handleCopyLink = () => { + navigator.clipboard.writeText(window.location.href); + toast.success("🔗 Shareable link copied to clipboard!"); + }; + if (loading) return
Loading...
; + if (!profile) return
User not found.
; + return (
- {profile && ( -
- -

{profile.login}

-

{profile.bio}

-
- )} +
+ Avatar +

{profile.login}

+

{profile.bio}

+ +

Pull Requests

- + {prs.length > 0 ? ( + + ) : ( +

No pull requests found for this user.

+ )}
); }