Add clear day option to calendar
- Add clearDayData function to remove specific day's usage - Add "Clear This Day" button in calendar edit dialog - Allows users to reset individual days without clearing all data Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9918432686
commit
cab5e5810a
@ -12,7 +12,7 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { UsageEntry, getUsageForDate, setUsageForDate } from '@/lib/storage';
|
||||
import { UsageEntry, getUsageForDate, setUsageForDate, clearDayData } from '@/lib/storage';
|
||||
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
||||
|
||||
interface UsageCalendarProps {
|
||||
@ -59,6 +59,17 @@ export function UsageCalendar({ usageData, substance, onDataUpdate }: UsageCalen
|
||||
setEditCount('');
|
||||
};
|
||||
|
||||
const handleClearDay = () => {
|
||||
if (selectedDate) {
|
||||
const dateStr = selectedDate.toISOString().split('T')[0];
|
||||
clearDayData(dateStr, substance);
|
||||
onDataUpdate();
|
||||
}
|
||||
setIsEditing(false);
|
||||
setSelectedDate(undefined);
|
||||
setEditCount('');
|
||||
};
|
||||
|
||||
const getUsageCount = useCallback((date: Date): number => {
|
||||
const dateStr = date.toISOString().split('T')[0];
|
||||
const entry = usageData.find((e) => e.date === dateStr && e.substance === substance);
|
||||
@ -179,6 +190,15 @@ export function UsageCalendar({ usageData, substance, onDataUpdate }: UsageCalen
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
<div className="pt-2 border-t">
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={handleClearDay}
|
||||
className="w-full"
|
||||
>
|
||||
Clear This Day
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@ -191,6 +191,13 @@ export function getCurrentWeekTarget(): number | null {
|
||||
return prefs.quitPlan.weeklyTargets[weekNumber];
|
||||
}
|
||||
|
||||
export function clearDayData(date: string, substance: 'nicotine' | 'weed'): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const data = getUsageData();
|
||||
const filtered = data.filter((e) => !(e.date === date && e.substance === substance));
|
||||
localStorage.setItem(USAGE_KEY, JSON.stringify(filtered));
|
||||
}
|
||||
|
||||
export function clearAllData(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.removeItem(USAGE_KEY);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user