import React, { useEffect, useMemo, useState } from 'react'; import { GitBranch } from 'lucide-react'; import { getCachedGitActivity } from '../lib/git'; import { formatDate, isToday, getWeekdayLabel } from '../lib/utils-habit'; import AnimatedCounter from './AnimatedCounter'; const GitActivityGrid = () => { const [{ dailyCounts }, setData] = useState(() => getCachedGitActivity()); const weeks = useMemo(() => { const today = new Date(); const todayDay = today.getDay(); const daysSinceMonday = (todayDay + 6) % 7; const mondayThisWeek = new Date(today); mondayThisWeek.setDate(today.getDate() - daysSinceMonday); const weeksArray = []; const totalWeeks = 52; for (let week = totalWeeks - 1; week >= 0; week--) { const weekDays = []; const monday = new Date(mondayThisWeek); monday.setDate(mondayThisWeek.getDate() - week * 7); for (let day = 0; day < 7; day++) { const date = new Date(monday); date.setDate(monday.getDate() + day); weekDays.push(date); } weeksArray.push(weekDays); } return weeksArray; }, []); const getOpacity = (count) => { if (!count) return 0.15; if (count < 2) return 0.35; if (count < 5) return 0.6; if (count < 10) return 0.8; return 1; }; useEffect(() => { // Display current cache only; syncing is done from Settings setData(getCachedGitActivity()); }, []); return (

Git Activity

{weeks.map((week, weekIndex) => (
{weekIndex % 4 === 0 && week[0].toLocaleDateString('en-US', { month: 'short' })}
{week.map((date, dayIndex) => { const dateStr = formatDate(date); const count = dailyCounts?.[dateStr] || 0; const isTodayCell = isToday(date); const isFuture = date > new Date(); return (
{/* Animated commit count for tooltip */} commits
); })}
))}
{[1, 2, 3, 4, 5, 6, 0].map((day) => (
{getWeekdayLabel(day)}
))}
); }; export default GitActivityGrid;