Cache versioned habit history and load visible calendar ranges

This commit is contained in:
syntaxbullet
2026-09-08 16:15:29 +02:00
parent 31e4f3b2ef
commit b4619dec33
8 changed files with 127 additions and 27 deletions

View File

@@ -1,3 +1,4 @@
import { CalendarCacheProvider } from "../components/CalendarCache";
import { Archive, Plus, Settings2 } from "lucide-react";
import { ArchivedHabits } from "../components/ArchivedHabits";
import { AccountSettings } from "../components/AccountSettings";
@@ -63,7 +64,7 @@ export function Home() {
</Card>
</section>
) : user ? (
<Dashboard key={user.id} user={user} onExpired={retry} />
<CalendarCacheProvider key={`${user.id}:${user.timezone}`}><Dashboard user={user} onExpired={retry} /></CalendarCacheProvider>
) : (
<Welcome onSignIn={signIn} />
)}
@@ -163,7 +164,6 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
const [today, setToday] = useState<TodayResponse | null>(null);
const [error, setError] = useState("");
const [revision, setRevision] = useState(0);
const [calendarRevision, setCalendarRevision] = useState(0);
const [habitRevisions, setHabitRevisions] = useState<Record<string, number>>({});
const [pendingHabits, setPendingHabits] = useState<Set<string>>(new Set());
const progressSaves = useRef(new Set<string>());
@@ -206,7 +206,6 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
setToday(data);
setNeedsRefresh(false);
setRevision((value) => value + 1);
setCalendarRevision((value) => value + 1);
}
})
.catch((error) => {
@@ -457,7 +456,7 @@ function Dashboard({ user, onExpired }: { user: PublicUser; onExpired: () => voi
key={habit.habitId}
habit={habit}
date={today.date}
revision={calendarRevision + (habitRevisions[habit.habitId] ?? 0)}
revision={habit.calendarRevision ?? habitRevisions[habit.habitId] ?? 0}
disabled={busy || pendingHabits.has(habit.habitId) || loading || needsRefresh}
onHistorySaved={() => setAttempt(value => value + 1)}
onUpdate={update}