forked from rupali-codes/LinksHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontributors.tsx
126 lines (115 loc) · 3.85 KB
/
contributors.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { FC } from 'react'
import Image from 'next/image'
import Link from 'next/link'
import type { GetStaticProps } from 'next'
interface Contributor {
id: number
avatar_url: string
name: string
login: string
contributions: number
}
export const getStaticProps: GetStaticProps<{
contributors: Contributor[]
}> = async () => {
try {
const response = await fetch(
'https://api.github.com/repos/rupali-codes/LinksHub/contributors'
)
if (response.ok) {
const contributors: Contributor[] = await response.json()
// Fetch contributor names
const updatedContributors: Contributor[] = []
for (const contributor of contributors) {
try {
const response = await fetch(
`https://api.github.com/users/${contributor.login}`
)
if (response.ok) {
const data = await response.json()
const updatedContributor: Contributor = {
...contributor,
name: data.name || contributor.login,
}
updatedContributors.push(updatedContributor)
} else {
console.error('Failed to fetch contributor name:', response.status)
}
} catch (error) {
console.error(
'Failed to fetch contributor name from GitHub API:',
error
)
}
}
return { props: { contributors: updatedContributors } }
} else {
console.error('Failed to fetch contributors data:', response.status)
}
} catch (error) {
console.error('Failed to fetch contributors data from GitHub API:', error)
}
return { props: { contributors: [] } }
}
const ContributorsPage: FC<{ contributors: Contributor[] }> = ({
contributors,
}) => {
const filteredContributors = contributors.filter(
(contributor) => contributor.contributions >= 6
)
const sortedContributors = filteredContributors.sort(
(a, b) => b.contributions - a.contributions
)
const buttonStyles =
'bg-violet-600 hover:bg-transparent text-white px-4 py-2 md:px-3 text-sm tracking-[.6px] rounded-md border border-dashed border-transparent duration-100 hover:border-violet-400 hover:text-violet-500 dark:hover:text-violet-400'
const linkProps = {
target: '_blank',
rel: 'noopener noreferrer',
className: buttonStyles,
}
return (
<div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5">
{sortedContributors.map((contributor) => (
<div
key={contributor.id}
className="bg-gray-100 rounded-3xl py-5 px-2 border border-dashed border-violet-500 dark:border-violet-400 shadow-lg dark:bg-gray-900 dark:text-gray-300 dark:shadow-sm flex flex-col"
>
<div className="flex justify-center">
<Image
src={contributor.avatar_url}
alt={contributor.login}
width={80}
height={80}
className=" rounded-full mb-4"
/>
</div>
<div className="text-center">
<div className="text-xl text-violet-600 dark:text-violet-400">
{contributor.name}
</div>
<div className="text-gray-400 mb-2 pb-4 pt-1">
{contributor.contributions} Contributions
</div>
</div>
<div className="flex justify-evenly mt-auto">
<Link
href={`https://github.com/${contributor.login}`}
{...linkProps}
>
GitHub
</Link>
<Link
href={`https://github.com/rupali-codes/LinksHub/commits?author=${contributor.login}`}
{...linkProps}
>
Contributions
</Link>
</div>
</div>
))}
</div>
</div>
)
}
export default ContributorsPage