-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9e8edb
commit 09ae096
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import Link from 'next/link'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
interface Contributor { | ||
html_url: string; | ||
avatar_url: string; | ||
login: string; | ||
contributions: number; | ||
} | ||
|
||
const Contributors = () => { | ||
const URL = 'https://api.github.com/repos/Avdhesh-Varshney/WebMasterLog/contributors?per_page=500'; | ||
const [contributors, setContributors] = useState<Contributor[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState<null | string>(null); | ||
const [hoveredContributor, setHoveredContributor] = useState<Contributor | null>(null); | ||
|
||
useEffect(() => { | ||
fetch(URL, { | ||
next: { | ||
revalidate: 86400, | ||
}, | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
setContributors(data); | ||
setLoading(false); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
setLoading(false); | ||
}); | ||
}, []); | ||
|
||
if (loading) return <div>Loading...</div>; | ||
if (error) return <div>Error: {error}</div>; | ||
console.log(contributors[0]) | ||
|
||
return ( | ||
<div className="bg-[#191c24] p-4 rounded-lg my-2"> | ||
<h1 className="text-5xl text-center mb-4">Our Valuable Contributors</h1> | ||
<div className="flex flex-wrap justify-center"> | ||
{contributors.length > 0 ? ( | ||
contributors.map((contributor, index) => ( | ||
<div | ||
key={index} | ||
className="relative mx-2 my-3" | ||
onMouseEnter={() => setHoveredContributor(contributor)} | ||
onMouseLeave={() => setHoveredContributor(null)} | ||
> | ||
<div style={{ width: '65px', height: '65px', clipPath: 'polygon(50% 0%, 91% 25%, 91% 75%, 50% 100%, 9% 75%, 9% 25%)' }}> | ||
<img src={contributor.avatar_url} alt={contributor.login} /> | ||
</div> | ||
{hoveredContributor === contributor && ( | ||
<div className="absolute -left-16 top-16 z-20 w-48 p-4 bg-[#191c24] border-[1px] border-blue-400 font-bold rounded-lg shadow-lg transition-opacity duration-300 animate-fadeIn flex flex-col items-center gap-2"> | ||
<Link href={contributor.html_url}> | ||
<img src={contributor.avatar_url} alt={contributor.login} className='rounded-lg w-32 h-32' /> | ||
</Link> | ||
<p className="text-base text-center">{contributor.login}</p> | ||
<p className='text-sm text-center'>Contributions: {contributor.contributions} 🏆</p> | ||
</div> | ||
)} | ||
</div> | ||
)) | ||
) : ( | ||
<p>API Limit Exceeded!</p> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Contributors; |