Update reminder settings to use dropdown time picker
This commit is contained in:
parent
1556cf69c6
commit
20872c9cc8
@ -1,15 +1,21 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { ReminderSettings } from '@/lib/storage';
|
import { ReminderSettings } from '@/lib/storage';
|
||||||
import { useNotifications } from '@/hooks/useNotifications';
|
import { useNotifications } from '@/hooks/useNotifications';
|
||||||
import { useTheme } from '@/lib/theme-context';
|
import { useTheme } from '@/lib/theme-context';
|
||||||
import { Bell, BellOff, BellRing, Check, X } from 'lucide-react';
|
import { Bell, BellOff, BellRing, Check, X } from 'lucide-react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select';
|
||||||
|
|
||||||
interface ReminderSettingsCardProps {
|
interface ReminderSettingsCardProps {
|
||||||
settings: ReminderSettings;
|
settings: ReminderSettings;
|
||||||
onSettingsChange: (settings: ReminderSettings) => void;
|
onSettingsChange: (settings: ReminderSettings) => void;
|
||||||
@ -21,7 +27,14 @@ export function ReminderSettingsCard({
|
|||||||
}: ReminderSettingsCardProps) {
|
}: ReminderSettingsCardProps) {
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
const { isSupported, permission, requestPermission } = useNotifications(settings);
|
const { isSupported, permission, requestPermission } = useNotifications(settings);
|
||||||
const [localTime, setLocalTime] = useState(settings.reminderTime);
|
|
||||||
|
// Parse current time for initial state
|
||||||
|
const [hours, minutes] = settings.reminderTime.split(':').map(Number);
|
||||||
|
const currentAmpm = hours >= 12 ? 'PM' : 'AM';
|
||||||
|
const currentHour12 = hours % 12 || 12; // Convert 0 -> 12, 13 -> 1, etc.
|
||||||
|
|
||||||
|
const hourString = currentHour12.toString().padStart(2, '0');
|
||||||
|
const minuteString = minutes.toString().padStart(2, '0');
|
||||||
|
|
||||||
const handleToggle = async () => {
|
const handleToggle = async () => {
|
||||||
if (!settings.enabled && permission !== 'granted') {
|
if (!settings.enabled && permission !== 'granted') {
|
||||||
@ -35,11 +48,16 @@ export function ReminderSettingsCard({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTimeChange = (newTime: string) => {
|
const updateTime = (newHourStr: string, newMinuteStr: string, newAmpmStr: string) => {
|
||||||
setLocalTime(newTime);
|
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}`;
|
||||||
|
|
||||||
onSettingsChange({
|
onSettingsChange({
|
||||||
...settings,
|
...settings,
|
||||||
reminderTime: newTime,
|
reminderTime: timeString,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,6 +75,10 @@ export function ReminderSettingsCard({
|
|||||||
|
|
||||||
const permissionStatus = getPermissionStatus();
|
const permissionStatus = getPermissionStatus();
|
||||||
|
|
||||||
|
// 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'));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className="backdrop-blur-xl border border-indigo-500/40 shadow-xl drop-shadow-lg hover-lift transition-all duration-300 overflow-hidden relative"
|
className="backdrop-blur-xl border border-indigo-500/40 shadow-xl drop-shadow-lg hover-lift transition-all duration-300 overflow-hidden relative"
|
||||||
@ -95,14 +117,12 @@ export function ReminderSettingsCard({
|
|||||||
<button
|
<button
|
||||||
onClick={handleToggle}
|
onClick={handleToggle}
|
||||||
disabled={!isSupported || permission === 'denied'}
|
disabled={!isSupported || permission === 'denied'}
|
||||||
className={`relative w-12 h-6 rounded-full transition-all duration-300 ${
|
className={`relative w-12 h-6 rounded-full transition-all duration-300 ${settings.enabled ? 'bg-indigo-500' : 'bg-white/20'
|
||||||
settings.enabled ? 'bg-indigo-500' : 'bg-white/20'
|
} ${!isSupported || permission === 'denied' ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`}
|
||||||
} ${!isSupported || permission === 'denied' ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`}
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`absolute top-1 w-4 h-4 rounded-full bg-white transition-all duration-300 ${
|
className={`absolute top-1 w-4 h-4 rounded-full bg-white transition-all duration-300 ${settings.enabled ? 'left-7' : 'left-1'
|
||||||
settings.enabled ? 'left-7' : 'left-1'
|
}`}
|
||||||
}`}
|
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -110,16 +130,65 @@ export function ReminderSettingsCard({
|
|||||||
{/* Time Picker */}
|
{/* Time Picker */}
|
||||||
{settings.enabled && (
|
{settings.enabled && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="reminderTime" className="text-white/70 text-sm">
|
<Label className="text-white/70 text-sm">
|
||||||
Reminder Time
|
Reminder Time
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<div className="flex gap-2">
|
||||||
id="reminderTime"
|
{/* Hour Select */}
|
||||||
type="time"
|
<div className="flex-1">
|
||||||
value={localTime}
|
<Select
|
||||||
onChange={(e) => handleTimeChange(e.target.value)}
|
value={hourString}
|
||||||
className="bg-white/10 border-white/20 text-white"
|
onValueChange={(val) => updateTime(val, minuteString, currentAmpm)}
|
||||||
/>
|
>
|
||||||
|
<SelectTrigger className="bg-white/10 border-white/20 text-white">
|
||||||
|
<SelectValue placeholder="Hour" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{hoursOptions.map((h) => (
|
||||||
|
<SelectItem key={h} value={h}>
|
||||||
|
{h}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Minute Select */}
|
||||||
|
<div className="flex-1">
|
||||||
|
<Select
|
||||||
|
value={minuteString}
|
||||||
|
onValueChange={(val) => updateTime(hourString, val, currentAmpm)}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="bg-white/10 border-white/20 text-white">
|
||||||
|
<SelectValue placeholder="Min" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{minutesOptions.map((m) => (
|
||||||
|
<SelectItem key={m} value={m}>
|
||||||
|
{m}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* AM/PM Select */}
|
||||||
|
<div className="w-24">
|
||||||
|
<Select
|
||||||
|
value={currentAmpm}
|
||||||
|
onValueChange={(val) => updateTime(hourString, minuteString, val)}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="bg-white/10 border-white/20 text-white">
|
||||||
|
<SelectValue placeholder="AM/PM" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="AM">AM</SelectItem>
|
||||||
|
<SelectItem value="PM">PM</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p className="text-xs text-white/50">
|
<p className="text-xs text-white/50">
|
||||||
You'll receive a reminder at this time each day
|
You'll receive a reminder at this time each day
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user