diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index 0287855..ab200ba 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -13,6 +13,22 @@ interface CalendarProps { onToggleHabit: (habitId: number, date: string) => void; } +// Add this utility function at the top of the file +const useIsMobile = () => { + const [isMobile, setIsMobile] = React.useState(window.innerWidth < 768); + + React.useEffect(() => { + const handleResize = () => { + setIsMobile(window.innerWidth < 768); + }; + + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }, []); + + return isMobile; +}; + export const Calendar: React.FC = ({ currentMonth, habits, @@ -22,6 +38,7 @@ export const Calendar: React.FC = ({ onToggleHabit }) => { const { theme } = useThemeContext(); + const isMobile = useIsMobile(); const daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; @@ -103,9 +120,17 @@ export const Calendar: React.FC = ({ return ( <> -
-
-

+
+
+

{currentMonth.toLocaleString('default', { month: 'long', year: 'numeric' })}

@@ -124,10 +149,14 @@ export const Calendar: React.FC = ({
-
+
{daysOfWeek.map(day => ( -
- {day} +
+ {isMobile ? day.charAt(0) : day}
))} @@ -181,51 +210,70 @@ export const Calendar: React.FC = ({
{dayNumber} {habits.length > 0 && ( -
+
showTooltip(e, date, completedHabits, incompleteHabits)} - onMouseLeave={hideTooltip} + {...(!isMobile ? { + onMouseEnter: (e) => showTooltip(e, date, completedHabits, incompleteHabits), + onMouseLeave: hideTooltip + } : {})} > -
- {isToday && ( -
- )} -
+
0 + ? 'text-green-700 dark:text-green-300' + : `${theme.text} opacity-75` + } + `}> + {completedHabits.length}/{habits.length} +
+
+ ) : ( +
+ {isToday && ( +
+ )} +
0 ? 'bg-green-100 dark:bg-green-900/30 shadow-[0_2px_10px] shadow-green-900/20 dark:shadow-green-100/20' : `bg-gray-100 dark:bg-gray-800 shadow-sm` } - `} - > - 0 - ? 'text-green-700 dark:text-green-300' - : 'text-gray-600 dark:text-gray-400' - } `}> - {completedHabits.length}/{habits.length} - + 0 + ? 'text-green-700 dark:text-green-300' + : 'text-gray-600 dark:text-gray-400' + } + `}> + {completedHabits.length}/{habits.length} + +
-
+ )}
)} @@ -236,8 +284,8 @@ export const Calendar: React.FC = ({
- {/* Updated tooltip portal with more subtle animations */} - {tooltipData && createPortal( + {/* Tooltip portal - only render on desktop */} + {!isMobile && tooltipData && createPortal(