diff --git a/src/components/UserHeader.tsx b/src/components/UserHeader.tsx index 36c2292..5e50b69 100644 --- a/src/components/UserHeader.tsx +++ b/src/components/UserHeader.tsx @@ -14,6 +14,13 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; @@ -41,6 +48,30 @@ export function UserHeader({ user, preferences }: UserHeaderProps) { const { theme, toggleTheme } = useTheme(); const { isSupported, permission, requestPermission } = useNotifications(reminderSettings); + // Helper to parse time string + const [parsedHours, parsedMinutes] = reminderSettings.reminderTime.split(':').map(Number); + const currentAmpm = parsedHours >= 12 ? 'PM' : 'AM'; + const currentHour12 = parsedHours % 12 || 12; + const hourString = currentHour12.toString().padStart(2, '0'); + const minuteString = parsedMinutes.toString().padStart(2, '0'); + + const updateTime = async (newHourStr: string, newMinuteStr: string, newAmpmStr: string) => { + let h = parseInt(newHourStr); + if (newAmpmStr === 'PM' && h !== 12) h += 12; + if (newAmpmStr === 'AM' && h === 12) h = 0; + + const timeString = `${h.toString().padStart(2, '0')}:${newMinuteStr}`; + setLocalTime(timeString); + + const newSettings = { ...reminderSettings, reminderTime: timeString }; + setReminderSettings(newSettings); + await saveReminderSettings(newSettings); + }; + + // Generate options + const hoursOptions = Array.from({ length: 12 }, (_, i) => (i + 1).toString().padStart(2, '0')); + const minutesOptions = Array.from({ length: 12 }, (_, i) => (i * 5).toString().padStart(2, '0')); + useEffect(() => { const loadData = async () => { // If preferences passed from parent, use them. Otherwise fetch. @@ -71,12 +102,7 @@ export function UserHeader({ user, preferences }: UserHeaderProps) { await saveReminderSettings(newSettings); }; - const handleTimeChange = async (newTime: string) => { - setLocalTime(newTime); - const newSettings = { ...reminderSettings, reminderTime: newTime }; - setReminderSettings(newSettings); - await saveReminderSettings(newSettings); - }; + const handleFrequencyChange = async (newFrequency: 'daily' | 'hourly') => { setLocalFrequency(newFrequency); @@ -313,15 +339,64 @@ export function UserHeader({ user, preferences }: UserHeaderProps) { {/* Time Picker (Only for Daily) */} {reminderSettings.enabled && localFrequency === 'daily' && (
-