Skip to content

Commit 2a9b668

Browse files
committed
fix: if not find developer languages, disable programming languages view
1 parent 527fe3a commit 2a9b668

6 files changed

Lines changed: 188 additions & 116 deletions

File tree

src/app/developers/[id]/DeveloperDetailClient.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ProfileCardWidget from "~/developer/widgets/profile-card";
1919
import ActivityListViewWidget from "~/developer/views/activity-list";
2020
import { ProgrammingLanguagesBar } from "../../../components/event/ProgrammingLanguagesBar";
2121
import { ProgrammingLanguagesPie } from "../../../components/event/ProgrammingLanguagesPie";
22+
import { useGitHubStats } from "../../../hooks/useGitHubStats";
2223

2324
import { resolveChartOptions } from "./helper";
2425

@@ -35,6 +36,10 @@ export default function DeveloperDetailClient({
3536
repositories,
3637
recentActivity,
3738
}: DeveloperDetailProps) {
39+
const { data: githubStats, loading: githubStatsLoading } = useGitHubStats(developer?.username || null);
40+
const githubLanguages = githubStats?.languages ?? [];
41+
const shouldShowGitHubLanguages = githubStatsLoading || githubLanguages.length > 0;
42+
3843
// Show loading skeleton while data is being fetched
3944
if (!developer) {
4045
return (
@@ -78,17 +83,25 @@ export default function DeveloperDetailClient({
7883
<div className="animate-fade-in">
7984
<ProfileCardWidget className="mb-4" developer={developer} />
8085
</div>
81-
<div className="animate-slide-up" style={{ animationDelay: "50ms" }}>
82-
<div className="mb-4">
83-
<h5 className="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2">
84-
Programming Languages
85-
</h5>
86-
<div className="grid gap-4 lg:grid-cols-2">
87-
<ProgrammingLanguagesBar username={developer.username} />
88-
<ProgrammingLanguagesPie username={developer.username} />
86+
{shouldShowGitHubLanguages && (
87+
<div className="animate-slide-up" style={{ animationDelay: "50ms" }}>
88+
<div className="mb-4">
89+
<h5 className="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2">
90+
Programming Languages
91+
</h5>
92+
<div className="grid gap-4 lg:grid-cols-2">
93+
<ProgrammingLanguagesBar
94+
languages={githubLanguages}
95+
loading={githubStatsLoading}
96+
/>
97+
<ProgrammingLanguagesPie
98+
languages={githubLanguages}
99+
loading={githubStatsLoading}
100+
/>
101+
</div>
89102
</div>
90103
</div>
91-
</div>
104+
)}
92105
<div
93106
className="animate-slide-up mb-4"
94107
style={{ animationDelay: "200ms" }}

src/components/event/ProgrammingLanguagesBar.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
import { Code2, Cpu } from "lucide-react";
2-
import { useGitHubStats } from "../../hooks/useGitHubStats";
2+
import { useGitHubStats, type GitHubLanguage } from "../../hooks/useGitHubStats";
33

44
interface ProgrammingLanguagesBarProps {
5-
username: string;
5+
username?: string | null;
66
className?: string;
7+
languages?: GitHubLanguage[];
8+
loading?: boolean;
79
}
810

9-
export function ProgrammingLanguagesBar({ username, className = "" }: ProgrammingLanguagesBarProps) {
10-
const { data: githubData } = useGitHubStats(username);
11+
export function ProgrammingLanguagesBar({
12+
username,
13+
className = "",
14+
languages: providedLanguages,
15+
loading: forcedLoading,
16+
}: ProgrammingLanguagesBarProps) {
17+
const shouldFetch = !providedLanguages && !!username;
18+
const { data: githubData, loading } = useGitHubStats(shouldFetch ? (username ?? null) : null);
19+
const languages = providedLanguages ?? githubData?.languages ?? [];
20+
const isLoading = typeof forcedLoading === "boolean" ? forcedLoading : (shouldFetch ? loading : false);
21+
const hasLanguages = languages.length > 0;
22+
23+
if (!isLoading && !hasLanguages) {
24+
return null;
25+
}
1126

1227
return (
1328
<div className={`border border-border dark:border-border-dark rounded-xl p-4 bg-white dark:bg-surface-dark shadow-subtle ${className}`}>
1429
<div className="flex items-center gap-2 mb-4">
1530
<Code2 size={14} className="text-gray-600 dark:text-gray-400" />
1631
<h4 className="text-sm font-medium text-gray-900 dark:text-white">Programming Languages</h4>
17-
{githubData?.languages && (
32+
{hasLanguages && (
1833
<span className="text-xs text-gray-500 dark:text-gray-400 ml-auto">
19-
{githubData.languages.length}
34+
{languages.length}
2035
</span>
2136
)}
2237
</div>
2338

24-
{githubData?.languages && githubData.languages.length > 0 ? (
39+
{hasLanguages ? (
2540
<div className="space-y-3">
26-
{githubData.languages.slice(0, 5).map((language, index) => {
41+
{languages.slice(0, 5).map((language, index) => {
2742
const percentage = parseFloat(language.percentage.replace('%', ''));
2843
const skillLevel = percentage >= 80 ? "Expert" : percentage >= 65 ? "Proficient" : "Familiar";
2944

src/components/event/ProgrammingLanguagesPie.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from "recharts";
22
import { Code2 } from "lucide-react";
3-
import { useGitHubStats } from "../../hooks/useGitHubStats";
3+
import { useGitHubStats, type GitHubLanguage } from "../../hooks/useGitHubStats";
44

55
interface ProgrammingLanguagesPieProps {
6-
username: string;
6+
username?: string | null;
77
className?: string;
8+
languages?: GitHubLanguage[];
9+
loading?: boolean;
810
}
911

1012
// Balanced teal/green theme colors - not too bright, not too dark
@@ -17,14 +19,28 @@ const COLORS = [
1719
"#10b981", // emerald-500
1820
];
1921

20-
export function ProgrammingLanguagesPie({ username, className = "" }: ProgrammingLanguagesPieProps) {
21-
const { data: githubData } = useGitHubStats(username);
22+
export function ProgrammingLanguagesPie({
23+
username,
24+
className = "",
25+
languages: providedLanguages,
26+
loading: forcedLoading,
27+
}: ProgrammingLanguagesPieProps) {
28+
const shouldFetch = !providedLanguages && !!username;
29+
const { data: githubData, loading } = useGitHubStats(shouldFetch ? (username ?? null) : null);
30+
const languages = providedLanguages ?? githubData?.languages ?? [];
31+
const isLoading = typeof forcedLoading === "boolean" ? forcedLoading : (shouldFetch ? loading : false);
32+
const hasLanguages = languages.length > 0;
33+
const chartData = hasLanguages
34+
? languages.slice(0, 6).map(lang => ({
35+
name: lang.name,
36+
value: parseFloat(lang.percentage.replace('%', '')),
37+
percentage: lang.percentage,
38+
}))
39+
: [];
2240

23-
const chartData = githubData?.languages?.slice(0, 6).map(lang => ({
24-
name: lang.name,
25-
value: parseFloat(lang.percentage.replace('%', '')),
26-
percentage: lang.percentage,
27-
})) || [];
41+
if (!isLoading && !hasLanguages) {
42+
return null;
43+
}
2844

2945
const CustomTooltip = ({ active, payload }: { active?: boolean; payload?: Array<{ payload: { name: string; percentage: string } }> }) => {
3046
if (active && payload && payload.length) {
@@ -48,14 +64,14 @@ export function ProgrammingLanguagesPie({ username, className = "" }: Programmin
4864
<div className="flex items-center gap-2 mb-4">
4965
<Code2 size={14} className="text-gray-600 dark:text-gray-400" />
5066
<h4 className="text-sm font-medium text-gray-900 dark:text-white">Language Distribution</h4>
51-
{githubData?.languages && (
67+
{hasLanguages && (
5268
<span className="text-xs text-gray-500 dark:text-gray-400 ml-auto">
53-
Top {Math.min(6, githubData.languages.length)}
69+
Top {Math.min(6, languages.length)}
5470
</span>
5571
)}
5672
</div>
5773

58-
{githubData?.languages && githubData.languages.length > 0 ? (
74+
{hasLanguages ? (
5975
<div className="space-y-4">
6076
{/* Compact Chart */}
6177
<div className="h-32 flex items-center justify-center">

src/hooks/useGitHubStats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ interface GitHubStats {
1111
contributedTo: string;
1212
}
1313

14-
interface Language {
14+
export interface GitHubLanguage {
1515
name: string;
1616
percentage: string;
1717
}
1818

1919
interface GitHubStatsData {
2020
username: string;
2121
stats: GitHubStats | null;
22-
languages: Language[];
22+
languages?: GitHubLanguage[];
2323
}
2424

2525
interface UseGitHubStatsResult {

src/services/event/views/event-detail/EventDetail.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ContributionStatsChart from "../../../../components/ContributionStatsChar
1313
import EcosystemRankingChart from "../../../../components/EcosystemRankingChart";
1414
import EventAnalyticsOverview from "../../../../components/EventAnalyticsOverview";
1515
import EventAnalyticsSkeleton from "../../../../components/loading/EventAnalyticsSkeleton";
16+
import { useGitHubStats } from "../../../../hooks/useGitHubStats";
1617

1718
import type { EventReport } from "../../typing";
1819
import { fetchOne, fetchPublicEventDetail } from "../../repository/client";
@@ -29,6 +30,34 @@ interface EventAnalysisData {
2930
users_without_contributions: number;
3031
}
3132

33+
function ContestantProgrammingLanguages({ username }: { username: string }) {
34+
const { data, loading } = useGitHubStats(username || null);
35+
const languages = data?.languages ?? [];
36+
const shouldRender = loading || languages.length > 0;
37+
38+
if (!shouldRender) {
39+
return null;
40+
}
41+
42+
return (
43+
<div>
44+
<h5 className="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2">
45+
Programming Languages
46+
</h5>
47+
<div className="grid gap-4 lg:grid-cols-2">
48+
<ProgrammingLanguagesBar
49+
languages={languages}
50+
loading={loading}
51+
/>
52+
<ProgrammingLanguagesPie
53+
languages={languages}
54+
loading={loading}
55+
/>
56+
</div>
57+
</div>
58+
);
59+
}
60+
3261
function EventDetailView({ id, mode = 'admin', showParticipants }: EventDetailViewWidgetProps) {
3362
const isAdminMode = mode === 'admin';
3463
const shouldShowParticipants = showParticipants ?? isAdminMode;
@@ -420,15 +449,7 @@ function EventDetailView({ id, mode = 'admin', showParticipants }: EventDetailVi
420449
</div>
421450

422451
{/* Programming Languages Section - Two Column Layout */}
423-
<div>
424-
<h5 className="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2">
425-
Programming Languages
426-
</h5>
427-
<div className="grid gap-4 lg:grid-cols-2">
428-
<ProgrammingLanguagesBar username={contestant.username} />
429-
<ProgrammingLanguagesPie username={contestant.username} />
430-
</div>
431-
</div>
452+
<ContestantProgrammingLanguages username={contestant.username} />
432453

433454
{/* Ecosystem Scores Chart - Full Width */}
434455
<div>

0 commit comments

Comments
 (0)