-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #836 from souvikpramanikgit/add-contributor
Add Contributor Page
- Loading branch information
Showing
6 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,156 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import '../styles/ContributorsPage.css'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faGithub } from '@fortawesome/free-brands-svg-icons' | ||
import CountUp from 'react-countup' | ||
import axios from 'axios' | ||
const ContributorsPage = () => { | ||
const [contributors, setContributors] = useState([]) | ||
const [repoStats, setRepoStats] = useState({}) | ||
const [loading, setLoading] = useState(true) | ||
const fetchData = async () => { | ||
try { | ||
const contributorsResponse = await fetch( | ||
'https://api.github.com/repos/manikumarreddyu/AgroTech-AI/contributors' | ||
) | ||
const contributorsData = await contributorsResponse.json() | ||
|
||
const repoResponse = await fetch( | ||
'https://api.github.com/repos/manikumarreddyu/AgroTech-AI' | ||
) | ||
const repoData = await repoResponse.json() | ||
|
||
setContributors(contributorsData) | ||
setRepoStats(repoData) | ||
} catch (error) { | ||
console.error('Error fetching data:', error) | ||
setContributors([]) | ||
setRepoStats({}) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
fetchData() | ||
}, []) | ||
|
||
const renderStats = () => { | ||
const contributorsCount = contributors.length | ||
const stats = [ | ||
{ label: 'Contributors', value: contributorsCount, icon: 'users' }, | ||
{ | ||
label: 'Total Contributions', | ||
value: | ||
contributors.reduce( | ||
(sum, contributor) => sum + contributor.contributions, | ||
0 | ||
) || 0, | ||
icon: 'git-commit', | ||
}, | ||
{ | ||
label: 'GitHub Stars', | ||
value: repoStats.stargazers_count || 0, | ||
icon: 'star', | ||
}, | ||
{ | ||
label: 'Forks', | ||
value: repoStats.forks_count || 0, | ||
icon: 'git-branch', | ||
}, | ||
] | ||
|
||
return ( | ||
<div className="contributor-stats-grid" id="statsGrid"> | ||
{stats.map((stat) => ( | ||
<div className="contributor-stat-card" key={stat.label}> | ||
<div | ||
className="contributor-icon" | ||
dangerouslySetInnerHTML={{ | ||
__html: getIcon(stat.icon), | ||
}} | ||
/> | ||
<h3> | ||
<CountUp | ||
start={0} | ||
end={stat.value} | ||
duration={3} | ||
separator="," | ||
/> | ||
</h3> | ||
<p>{stat.label}</p> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
const renderContributors = () => { | ||
return ( | ||
<div | ||
className="contributor-contributors-grid" | ||
id="contributorsGrid" | ||
> | ||
{contributors.map((contributor) => ( | ||
<div | ||
className="contributor-contributor-card" | ||
key={contributor.login} | ||
> | ||
<img | ||
src={contributor.avatar_url} | ||
alt={contributor.login} | ||
/> | ||
<h3>{contributor.login}</h3> | ||
<p>{contributor.type}</p> | ||
<div className="contributor-contributions"> | ||
{contributor.contributions} Contributions | ||
</div> | ||
<div className="contributor-footer"> | ||
<a | ||
href={contributor.html_url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{getIcon('external-link')} | ||
<FontAwesomeIcon icon={faGithub} /> | ||
</a> | ||
{getIcon('github')} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
const getIcon = (name) => { | ||
const icons = { | ||
// svg icons | ||
} | ||
return icons[name] || '' | ||
} | ||
|
||
return ( | ||
<> | ||
<section className=" dark:bg-slate-900"> | ||
<div className="contributor-contributors"> | ||
{loading ? ( | ||
<div id="loading" className="contributor-loading"></div> | ||
) : ( | ||
<> | ||
<h2 className="text-green-500"> | ||
Project Statistics | ||
</h2> | ||
{renderStats()} | ||
<h2 className="text-green-700"> | ||
Meet Our Contributors | ||
</h2> | ||
{renderContributors()} | ||
</> | ||
)} | ||
</div> | ||
</section> | ||
</> | ||
) | ||
} | ||
|
||
export default ContributorsPage |
Oops, something went wrong.