Skip to content

Commit a0711fb

Browse files
committed
forgotten comp
1 parent fd72d8b commit a0711fb

File tree

1 file changed

+252
-0
lines changed

1 file changed

+252
-0
lines changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
import { useEffect, useState } from 'react';
2+
import { baseUrl } from '../lib/utils';
3+
4+
type Contributor = {
5+
login: string;
6+
avatar_url: string;
7+
html_url: string;
8+
contributions: number;
9+
name?: string;
10+
};
11+
12+
type Maintainer = {
13+
login: string;
14+
avatar_url: string;
15+
html_url: string;
16+
name?: string;
17+
bio?: string;
18+
contributions?: number;
19+
};
20+
21+
interface GitHubContributorsProps {
22+
initialContributors: Contributor[];
23+
initialMaintainer: Maintainer | null;
24+
}
25+
26+
export default function GitHubContributors({
27+
initialContributors,
28+
initialMaintainer,
29+
}: GitHubContributorsProps) {
30+
const [contributors, setContributors] = useState<Contributor[]>([]);
31+
const [maintainer, setMaintainer] = useState<Maintainer | null>(null);
32+
const [isLoading, setIsLoading] = useState(true);
33+
const [contributorsError, setContributorsError] = useState(false);
34+
const [maintainerError, setMaintainerError] = useState(false);
35+
// Data source is always 'static' since we don't fetch from client-side
36+
const [dataSource] = useState<'static' | 'live'>('static');
37+
38+
useEffect(() => {
39+
// Step 1: Initialize from static JSON file
40+
const initializeFromJSON = async () => {
41+
try {
42+
console.log('[Build Data] 🔄 Initializing contributors/maintainer from static JSON file...');
43+
const response = await fetch(baseUrl('build-data-contributors.json'));
44+
if (response.ok) {
45+
const data = await response.json();
46+
let loaded = false;
47+
if (data.contributors && Array.isArray(data.contributors) && data.contributors.length > 0) {
48+
setContributors(data.contributors);
49+
setContributorsError(false);
50+
loaded = true;
51+
}
52+
if (data.maintainer) {
53+
setMaintainer(data.maintainer);
54+
setMaintainerError(false);
55+
loaded = true;
56+
}
57+
if (loaded) {
58+
setDataSource('static');
59+
setIsLoading(false);
60+
console.log(
61+
`[Build Data] ✓ Initialized from static JSON: ${data.contributors?.length || 0} contributors, maintainer: ${data.maintainer ? 'Yes' : 'No'}`
62+
);
63+
return true;
64+
}
65+
}
66+
} catch (error) {
67+
console.error('[Build Data] ✗ Failed to initialize from static JSON:', error);
68+
}
69+
setIsLoading(false);
70+
return false;
71+
};
72+
73+
// No client-side fetching - GitHub API has CORS restrictions
74+
// Data is only loaded from static JSON files generated at build time
75+
initializeFromJSON();
76+
}, []);
77+
78+
return (
79+
<>
80+
{/* Current Maintainer */}
81+
<div>
82+
<h2 className="text-3xl font-bold mb-6 text-gray-900 dark:text-white">
83+
Current Maintainer
84+
{isLoading && (
85+
<span className="ml-2 text-sm font-normal opacity-75">(loading...)</span>
86+
)}
87+
</h2>
88+
{maintainerError && !maintainer ? (
89+
<div className="bg-yellow-50 dark:bg-yellow-900/20 border-2 border-yellow-400 rounded-lg p-6">
90+
<p className="text-gray-700 dark:text-gray-300">
91+
Unable to load maintainer information at this time. This may be due to GitHub API
92+
rate limits. Please visit{' '}
93+
<a
94+
href="https://github.com/Carreau"
95+
target="_blank"
96+
rel="noopener noreferrer"
97+
className="text-theme-secondary hover:text-theme-secondary/80 transition-colors underline"
98+
>
99+
@Carreau's GitHub profile
100+
</a>{' '}
101+
directly.
102+
</p>
103+
</div>
104+
) : maintainer ? (
105+
<div className="gradient-stats-cyan-blue border-2 border-theme-secondary rounded-lg p-8">
106+
<div className="flex flex-col sm:flex-row items-center sm:items-start gap-6">
107+
<a
108+
href={maintainer.html_url}
109+
target="_blank"
110+
rel="noopener noreferrer"
111+
className="flex-shrink-0 group"
112+
>
113+
<img
114+
src={maintainer.avatar_url}
115+
alt={`${maintainer.name}'s avatar`}
116+
className="w-24 h-24 rounded-full border-4 border-theme-secondary group-hover:scale-110 transition-transform"
117+
/>
118+
</a>
119+
<div className="flex-1 text-center sm:text-left">
120+
<a
121+
href={maintainer.html_url}
122+
target="_blank"
123+
rel="noopener noreferrer"
124+
className="block"
125+
>
126+
<h3 className="text-2xl font-bold text-gray-900 dark:text-white mb-1 hover:text-theme-secondary transition-colors">
127+
{maintainer.name}
128+
</h3>
129+
<p className="text-theme-secondary mb-3">@{maintainer.login}</p>
130+
</a>
131+
{maintainer.contributions !== undefined && (
132+
<p className="text-gray-600 dark:text-gray-400 mb-2">
133+
{maintainer.contributions}{' '}
134+
{maintainer.contributions === 1 ? 'contribution' : 'contributions'}
135+
</p>
136+
)}
137+
{maintainer.bio && (
138+
<p className="text-gray-600 dark:text-gray-400">{maintainer.bio}</p>
139+
)}
140+
</div>
141+
</div>
142+
</div>
143+
) : !maintainer ? (
144+
<div className="bg-yellow-50 dark:bg-yellow-900/20 border-2 border-yellow-400 rounded-lg p-6">
145+
<p className="text-gray-700 dark:text-gray-300">
146+
Unable to load maintainer information at this time. Please visit{' '}
147+
<a
148+
href="https://github.com/Carreau"
149+
target="_blank"
150+
rel="noopener noreferrer"
151+
className="text-theme-secondary hover:text-theme-secondary/80 transition-colors underline"
152+
>
153+
@Carreau's GitHub profile
154+
</a>{' '}
155+
directly.
156+
</p>
157+
</div>
158+
) : null}
159+
</div>
160+
161+
{/* Developers */}
162+
<div>
163+
<h2 className="text-3xl font-bold mb-4 text-gray-900 dark:text-white">
164+
Developers & Contributors
165+
</h2>
166+
<p className="text-gray-600 dark:text-gray-400 mb-6">
167+
IPython is built and maintained by a vibrant community of developers and contributors
168+
from around the world. Here are some of the key contributors to the project:
169+
</p>
170+
{contributorsError && contributors.length === 0 ? (
171+
<div className="bg-yellow-50 dark:bg-yellow-900/20 border-2 border-yellow-400 rounded-lg p-6">
172+
<p className="text-gray-700 dark:text-gray-300 mb-2">
173+
Unable to load contributors at this time. This may be due to GitHub API rate limits.
174+
</p>
175+
<p className="text-gray-700 dark:text-gray-300">
176+
Please visit our{' '}
177+
<a
178+
href="https://github.com/ipython/ipython/graphs/contributors"
179+
target="_blank"
180+
rel="noopener noreferrer"
181+
className="text-theme-secondary hover:text-theme-secondary/80 transition-colors underline"
182+
>
183+
GitHub contributors page
184+
</a>{' '}
185+
to see all contributors.
186+
</p>
187+
</div>
188+
) : contributors.length > 0 ? (
189+
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
190+
{contributors
191+
.filter((c) => c.login !== 'Carreau')
192+
.map((contributor) => (
193+
<a
194+
key={contributor.login}
195+
href={contributor.html_url}
196+
target="_blank"
197+
rel="noopener noreferrer"
198+
className="flex flex-col items-center p-4 rounded-lg border border-gray-200 dark:border-ipython-slate hover:border-theme-secondary hover:shadow-lg dark:hover:shadow-xl dark:hover:shadow-theme-secondary/20 transition-all group"
199+
>
200+
<img
201+
src={contributor.avatar_url}
202+
alt={`${contributor.name || contributor.login}'s avatar`}
203+
className="w-16 h-16 rounded-full mb-2 group-hover:scale-110 transition-transform"
204+
loading="lazy"
205+
/>
206+
<span className="text-sm font-medium text-gray-900 dark:text-white text-center truncate w-full">
207+
{contributor.name || contributor.login}
208+
</span>
209+
<span className="text-xs text-gray-500 dark:text-gray-400 text-center truncate w-full">
210+
@{contributor.login}
211+
</span>
212+
<span className="text-xs text-gray-500 dark:text-gray-400">
213+
{contributor.contributions}{' '}
214+
{contributor.contributions === 1 ? 'contribution' : 'contributions'}
215+
</span>
216+
</a>
217+
))}
218+
</div>
219+
) : contributors.length === 0 ? (
220+
<div className="bg-yellow-50 dark:bg-yellow-900/20 border-2 border-yellow-400 rounded-lg p-6">
221+
<p className="text-gray-700 dark:text-gray-300 mb-2">
222+
Unable to load contributors at this time.
223+
</p>
224+
<p className="text-gray-700 dark:text-gray-300">
225+
Please visit our{' '}
226+
<a
227+
href="https://github.com/ipython/ipython/graphs/contributors"
228+
target="_blank"
229+
rel="noopener noreferrer"
230+
className="text-theme-secondary hover:text-theme-secondary/80 transition-colors underline"
231+
>
232+
GitHub contributors page
233+
</a>{' '}
234+
to see all contributors.
235+
</p>
236+
</div>
237+
) : null}
238+
<p className="text-gray-600 dark:text-gray-400 mt-6">
239+
Want to contribute? Check out our{' '}
240+
<a
241+
href="https://github.com/ipython/ipython"
242+
className="text-theme-secondary hover:text-theme-secondary/80 transition-colors"
243+
>
244+
GitHub repository
245+
</a>{' '}
246+
to get started!
247+
</p>
248+
</div>
249+
250+
</>
251+
);
252+
}

0 commit comments

Comments
 (0)