|
3 | 3 | import { useEffect, useState } from 'react'; |
4 | 4 |
|
5 | 5 | interface Contributor { |
6 | | - login: string; |
7 | | - avatar_url: string; |
8 | | - html_url: string; |
9 | | - contributions: number; |
| 6 | + login: string; |
| 7 | + avatar_url: string; |
| 8 | + html_url: string; |
| 9 | + contributions: number; |
10 | 10 | } |
11 | 11 |
|
12 | 12 | export function ContributorGrid() { |
13 | | - const [contributors, setContributors] = useState<Contributor[]>([]); |
14 | | - const [loading, setLoading] = useState(true); |
| 13 | + const [contributors, setContributors] = useState<Contributor[]>([]); |
| 14 | + const [loading, setLoading] = useState(true); |
15 | 15 |
|
16 | | - useEffect(() => { |
17 | | - fetch('/api/contributors') |
18 | | - .then(res => res.json()) |
19 | | - .then(data => { |
20 | | - if (Array.isArray(data)) { |
21 | | - setContributors(data); |
22 | | - } |
23 | | - }) |
24 | | - .catch(err => console.error('Failed to fetch contributors:', err)) |
25 | | - .finally(() => setLoading(false)); |
26 | | - }, []); |
| 16 | + useEffect(() => { |
| 17 | + fetch( |
| 18 | + 'https://api.github.com/repos/margelo/react-native-quick-crypto/contributors?per_page=100', |
| 19 | + ) |
| 20 | + .then(res => res.json()) |
| 21 | + .then(data => { |
| 22 | + if (Array.isArray(data)) { |
| 23 | + const humans = data.filter( |
| 24 | + (c: Contributor) => !c.login.toLowerCase().includes('[bot]'), |
| 25 | + ); |
| 26 | + setContributors(humans); |
| 27 | + } |
| 28 | + }) |
| 29 | + .catch(err => console.error('Failed to fetch contributors:', err)) |
| 30 | + .finally(() => setLoading(false)); |
| 31 | + }, []); |
27 | 32 |
|
28 | | - // Sort by contributions (descending) |
29 | | - const sortedContributors = contributors.sort((a, b) => b.contributions - a.contributions); |
| 33 | + // Sort by contributions (descending) |
| 34 | + const sortedContributors = contributors.sort( |
| 35 | + (a, b) => b.contributions - a.contributions, |
| 36 | + ); |
30 | 37 |
|
31 | | - if (loading) { |
32 | | - return <div className="text-sm text-fd-muted-foreground animate-pulse my-6">Loading contributors...</div>; |
33 | | - } |
34 | | - |
35 | | - if (contributors.length === 0) { |
36 | | - return ( |
37 | | - <div className="flex flex-col items-center justify-center p-8 border border-dashed border-fd-border rounded-lg bg-fd-card/50"> |
38 | | - <p className="text-sm text-fd-muted-foreground">No contributors found.</p> |
39 | | - </div> |
40 | | - ); |
41 | | - } |
| 38 | + if (loading) { |
| 39 | + return ( |
| 40 | + <div className="text-sm text-fd-muted-foreground animate-pulse my-6"> |
| 41 | + Loading contributors... |
| 42 | + </div> |
| 43 | + ); |
| 44 | + } |
42 | 45 |
|
| 46 | + if (contributors.length === 0) { |
43 | 47 | return ( |
44 | | - <div className="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-3"> |
45 | | - {sortedContributors.map((c) => ( |
46 | | - <a |
47 | | - key={c.login} |
48 | | - href={c.html_url} |
49 | | - target="_blank" |
50 | | - className="flex flex-col items-center bg-fd-card border border-fd-border rounded-lg hover:border-fd-primary/50 hover:bg-fd-secondary/30 transition-all no-underline group overflow-hidden p-0" |
51 | | - > |
52 | | - <img |
53 | | - src={c.avatar_url} |
54 | | - alt={c.login} |
55 | | - className="w-full aspect-square object-cover transition-transform group-hover:scale-105 !m-0 block" |
56 | | - /> |
57 | | - <div className="w-full p-2 text-center border-t border-fd-border/50 bg-fd-card/50"> |
58 | | - <span className="text-xs font-medium text-fd-foreground truncate block group-hover:text-fd-primary transition-colors"> |
59 | | - {c.login} |
60 | | - </span> |
61 | | - </div> |
62 | | - </a> |
63 | | - ))} |
64 | | - </div> |
| 48 | + <div className="flex flex-col items-center justify-center p-8 border border-dashed border-fd-border rounded-lg bg-fd-card/50"> |
| 49 | + <p className="text-sm text-fd-muted-foreground"> |
| 50 | + No contributors found. |
| 51 | + </p> |
| 52 | + </div> |
65 | 53 | ); |
| 54 | + } |
| 55 | + |
| 56 | + return ( |
| 57 | + <div className="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-3"> |
| 58 | + {sortedContributors.map(c => ( |
| 59 | + <a |
| 60 | + key={c.login} |
| 61 | + href={c.html_url} |
| 62 | + target="_blank" |
| 63 | + className="flex flex-col items-center bg-fd-card border border-fd-border rounded-lg hover:border-fd-primary/50 hover:bg-fd-secondary/30 transition-all no-underline group overflow-hidden p-0"> |
| 64 | + <img |
| 65 | + src={c.avatar_url} |
| 66 | + alt={c.login} |
| 67 | + className="w-full aspect-square object-cover transition-transform group-hover:scale-105 !m-0 block" |
| 68 | + /> |
| 69 | + <div className="w-full p-2 text-center border-t border-fd-border/50 bg-fd-card/50"> |
| 70 | + <span className="text-xs font-medium text-fd-foreground truncate block group-hover:text-fd-primary transition-colors"> |
| 71 | + {c.login} |
| 72 | + </span> |
| 73 | + </div> |
| 74 | + </a> |
| 75 | + ))} |
| 76 | + </div> |
| 77 | + ); |
66 | 78 | } |
0 commit comments