diff --git a/app/customize/components/ThemeQuickPresets.tsx b/app/customize/components/ThemeQuickPresets.tsx index 823f5d6b..ca9e0b83 100644 --- a/app/customize/components/ThemeQuickPresets.tsx +++ b/app/customize/components/ThemeQuickPresets.tsx @@ -508,7 +508,6 @@ const ICON_MAP: Record ReactElement> = { nord: (c) => , synthwave: (c) => , gruvbox: (c) => , - aurora_cyberpunk: (c) => , highcontrast: (c) => , aurora_cyberpunk: (c) => , catppuccin_latte: (c) => , diff --git a/lib/github.test.ts b/lib/github.test.ts index a1107ba2..c163bfa2 100644 --- a/lib/github.test.ts +++ b/lib/github.test.ts @@ -9,7 +9,7 @@ import { GITHUB_CACHE_TTL_MS, validateGitHubUsername, cacheKey, - buildCommitClock, + buildInsights, fetchOrgMembers, getOrgDashboardData, getWrappedData, @@ -433,8 +433,6 @@ describe('getFullDashboardData', () => { { name: 'Rust', percentage: 33, color: '#dea584' }, ]); expect(result.insights).toBeDefined(); - expect(result.commitClock).toBeDefined(); - expect(result.commitClock).toHaveLength(7); }); it('maps contribution counts to correct intensity levels', async () => { @@ -648,27 +646,44 @@ describe('cacheKey', () => { expect(cacheKey('contributions', 'DeepSikha', '2025')).toBe('contributions:deepsikha:2025'); }); }); +describe('buildInsights', () => { + it('uses active streak message when current streak > 3', () => { + const result = buildInsights( + { + totalContributions: 120, + currentStreak: 7, + longestStreak: 20, + }, + [{ name: 'TypeScript' }] + ); -describe('buildCommitClock', () => { - it('aggregates commits correctly by day of week', () => { - const allDays = [ - { date: '2024-06-09', contributionCount: 2 }, // Sun - { date: '2024-06-10', contributionCount: 5 }, // Mon - { date: '2024-06-10', contributionCount: 3 }, // Mon - { date: '2024-06-12', contributionCount: 4 }, // Wed - ]; - - const result = buildCommitClock(allDays); - - expect(result).toEqual([ - { day: 'Sun', commits: 2 }, - { day: 'Mon', commits: 8 }, - { day: 'Tue', commits: 0 }, - { day: 'Wed', commits: 4 }, - { day: 'Thu', commits: 0 }, - { day: 'Fri', commits: 0 }, - { day: 'Sat', commits: 0 }, - ]); + expect(result[2].text).toContain('active 7-day streak'); + }); + + it('uses longest streak message when current streak <= 3', () => { + const result = buildInsights( + { + totalContributions: 120, + currentStreak: 2, + longestStreak: 15, + }, + [{ name: 'Rust' }] + ); + + expect(result[2].text).toContain('15 days'); + }); + + it('falls back to Unknown when languages list is empty', () => { + const result = buildInsights( + { + totalContributions: 50, + currentStreak: 1, + longestStreak: 5, + }, + [] + ); + + expect(result[1].text).toContain('Unknown'); }); }); diff --git a/lib/github.ts b/lib/github.ts index 3654ac34..b7d944ba 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -452,6 +452,46 @@ export function generateAchievements(totalContributions: number, currentStreak: } return achievements; } +type StreakStats = { + totalContributions: number; + currentStreak: number; + longestStreak: number; +}; + +type Language = { + name: string; +}; + +export function buildInsights(streakStats: StreakStats, languages: Language[]) { + const insights = [ + { + id: '1', + icon: 'Flame', + text: `You have a total of ${streakStats.totalContributions} contributions this year.`, + }, + { + id: '2', + icon: 'Code', + text: `Your primary language is ${languages[0]?.name || 'Unknown'}.`, + }, + ]; + + if (streakStats.currentStreak > 3) { + insights.push({ + id: '3', + icon: 'Zap', + text: `You are currently on an active ${streakStats.currentStreak}-day streak! Keep it going!`, + }); + } else { + insights.push({ + id: '3', + icon: 'Star', + text: `Your longest coding streak is ${streakStats.longestStreak} days!`, + }); + } + + return insights; +} export function buildCommitClock(allDays: ContributionDay[]) { const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; @@ -553,29 +593,20 @@ export async function getFullDashboardData(username: string, options: FetchOptio streakStats.currentStreak ); - const insights = [ - { - id: '1', - icon: 'Flame', - text: `You have a total of ${streakStats.totalContributions} contributions this year.`, - }, - { id: '2', icon: 'Code', text: `Your primary language is ${languages[0]?.name || 'Unknown'}.` }, - ]; - if (streakStats.currentStreak > 3) { - insights.push({ - id: '3', - icon: 'Zap', - text: `You are currently on an active ${streakStats.currentStreak}-day streak! Keep it going!`, - }); - } else { - insights.push({ - id: '3', - icon: 'Star', - text: `Your longest coding streak is ${streakStats.longestStreak} days!`, - }); - } + // 4. Insights Generation + const insights = buildInsights(streakStats, languages); - const commitClock = buildCommitClock(allDays); + // Aggregate real contribution data by day of week from the already-fetched calendar + const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; + const dayTotals = new Array(7).fill(0); + for (const day of allDays) { + const dow = new Date(day.date).getUTCDay(); + dayTotals[dow] += day.contributionCount; + } + const commitClock = dayNames.map((name, i) => ({ + day: name, + commits: dayTotals[i], + })); return { profile,