Files
HaBit/components/layout/app-data-prefetcher.tsx
Harkamal Randhawa d5e80ec380 Finish interrupted features: tab prefetch, pet viewport, and home logo.
Add shared quiz/habits tab cache with nav hover prefetch and AppDataPrefetcher,
make the pet screen fill and center the viewport, and point the HaBit logo to /.
2026-05-24 04:57:13 -06:00

37 lines
786 B
TypeScript

"use client";
import { useEffect } from "react";
import { HABIT_PET_DATA_UPDATED_EVENT } from "@/lib/app-events";
import {
invalidateAppTabDataCache,
prefetchAppTabData,
} from "@/lib/app-tab-data-cache";
type AppDataPrefetcherProps = {
enabled: boolean;
};
export function AppDataPrefetcher({ enabled }: AppDataPrefetcherProps) {
useEffect(() => {
if (!enabled) {
return;
}
void prefetchAppTabData();
const handleDataUpdated = () => {
invalidateAppTabDataCache();
void prefetchAppTabData({ force: true });
};
window.addEventListener(HABIT_PET_DATA_UPDATED_EVENT, handleDataUpdated);
return () => {
window.removeEventListener(HABIT_PET_DATA_UPDATED_EVENT, handleDataUpdated);
};
}, [enabled]);
return null;
}