From bb64bacd1e429fae9378a8d91163fba3cc24a7d3 Mon Sep 17 00:00:00 2001 From: count0 Date: Mon, 13 Oct 2025 18:54:06 +0200 Subject: [PATCH] Update the minigrid responsiveness and visibility --- src/components/MiniGrid.jsx | 50 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/components/MiniGrid.jsx b/src/components/MiniGrid.jsx index b7f0984..0335423 100644 --- a/src/components/MiniGrid.jsx +++ b/src/components/MiniGrid.jsx @@ -7,8 +7,15 @@ const MiniGrid = ({ habit, onUpdate }) => { const today = new Date(); // Show fewer days on mobile for better aspect ratio const isMobile = window.innerWidth < 640; // Tailwind 'sm' breakpoint - const numDays = isMobile ? 14 : 28; + const numDays = isMobile ? 11 : 28; const days = []; + const scrollRef = React.useRef(null); + + React.useEffect(() => { + if (scrollRef.current) { + scrollRef.current.scrollLeft = scrollRef.current.scrollWidth; + } + }, [numDays, habit.completions]); for (let i = numDays - 1; i >= 0; i--) { const date = new Date(today); @@ -23,31 +30,34 @@ const MiniGrid = ({ habit, onUpdate }) => { }; return ( -
+
{days.map((date, index) => { const dateStr = formatDate(date); const isCompleted = habit.completions.includes(dateStr); const intensity = isCompleted ? getColorIntensity(habit.completions, dateStr) : 0; const isTodayCell = isToday(date); - + const dayLetter = date.toLocaleDateString('en-US', { weekday: 'short' })[0]; + return ( - handleCellClick(e, date)} - className="habit-cell flex w-8 h-8 rounded-2xl transition-all" - style={{ - backgroundColor: isCompleted - ? habit.color - : 'transparent', - opacity: isCompleted ? 0.3 + (intensity * 0.7) : 1, - border: isTodayCell - ? `2px solid ${habit.color}` - : `1px solid ${habit.color}20`, - }} - title={dateStr} - /> +
+ handleCellClick(e, date)} + className={`habit-cell flex w-8 h-8 transition-all ${isTodayCell ? 'rounded-md' : 'rounded-2xl'}`} + style={{ + backgroundColor: isCompleted + ? habit.color + : 'transparent', + opacity: isCompleted ? 0.3 + (intensity * 0.7) : 1, + border: isTodayCell + ? `2px solid ${habit.color}` + : `1px solid ${habit.color}20`, + }} + title={dateStr} + /> + {dayLetter} +
); })}