diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1b98a..74b1cd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## Version 0.2.2 + +### Changed + +* persist "show all" settings in browser (#72) + +### Fixed + +* nav bar spacing +* completion count badge + ## Version 0.2.1 ### Changed diff --git a/app/calendar/page.tsx b/app/calendar/page.tsx index 7f39efd..8993563 100644 --- a/app/calendar/page.tsx +++ b/app/calendar/page.tsx @@ -1,6 +1,7 @@ import Layout from '@/components/Layout' import HabitCalendar from '@/components/HabitCalendar' import { ViewToggle } from '@/components/ViewToggle' +import CompletionCountBadge from '@/components/CompletionCountBadge' export default function CalendarPage() { return ( diff --git a/app/debug/habits/page.tsx b/app/debug/habits/page.tsx new file mode 100644 index 0000000..9ae7e84 --- /dev/null +++ b/app/debug/habits/page.tsx @@ -0,0 +1,70 @@ +'use client' + +import { useHabits } from "@/hooks/useHabits"; +import { habitsAtom, settingsAtom } from "@/lib/atoms"; +import { Habit } from "@/lib/types"; +import { useAtom } from "jotai"; +import { DateTime } from "luxon"; + + + +type CompletionCache = { + [dateKey: string]: { // dateKey format: "YYYY-MM-DD" + [habitId: string]: number // number of completions on that date + } +} + + +export default function DebugPage() { + const [habits] = useAtom(habitsAtom); + const [settings] = useAtom(settingsAtom); + + function buildCompletionCache(habits: Habit[], timezone: string): CompletionCache { + const cache: CompletionCache = {}; + + habits.forEach(habit => { + habit.completions.forEach(utcTimestamp => { + // Convert UTC timestamp to local date string in specified timezone + const localDate = DateTime + .fromISO(utcTimestamp) + .setZone(timezone) + .toFormat('yyyy-MM-dd'); + + if (!cache[localDate]) { + cache[localDate] = {}; + } + + // Increment completion count for this habit on this date + cache[localDate][habit.id] = (cache[localDate][habit.id] || 0) + 1; + }); + }); + + return cache; + } + + function getCompletedHabitsForDate( + habits: Habit[], + date: DateTime, + timezone: string, + completionCache: CompletionCache + ): Habit[] { + const dateKey = date.setZone(timezone).toFormat('yyyy-MM-dd'); + const dateCompletions = completionCache[dateKey] || {}; + + return habits.filter(habit => { + const completionsNeeded = habit.targetCompletions || 1; + const completionsAchieved = dateCompletions[habit.id] || 0; + return completionsAchieved >= completionsNeeded; + }); + } + + const habitCache = buildCompletionCache(habits.habits, settings.system.timezone); + + return ( +