"use client"; import { useCallback, useEffect, useState } from "react"; import { DailyQuizForm } from "@/components/daily-quiz/daily-quiz-form"; import { HabitTracker } from "@/components/habits/habit-tracker"; import { JournalCalendar } from "@/components/journal/journal-calendar"; import { PetHabitat } from "@/components/pet/pet-habitat"; import { HABIT_PET_DATA_UPDATED_EVENT } from "@/lib/app-events"; import { getAvatarCustomization, type AvatarCustomization, } from "@/lib/avatar-customization-storage"; export function AvatarPageContent() { const [customization, setCustomization] = useState( null, ); const [loadError, setLoadError] = useState(null); const loadCustomization = useCallback(async () => { try { setLoadError(null); setCustomization(await getAvatarCustomization()); } catch (error) { setLoadError( error instanceof Error ? error.message : "Could not load your avatar.", ); } }, []); useEffect(() => { void loadCustomization(); window.addEventListener(HABIT_PET_DATA_UPDATED_EVENT, loadCustomization); return () => { window.removeEventListener(HABIT_PET_DATA_UPDATED_EVENT, loadCustomization); }; }, [loadCustomization]); useEffect(() => { const hash = window.location.hash.replace("#", ""); if (hash === "bit-daily-quiz") { window.location.hash = "bit-daily-check-in"; } }, []); if (loadError) { return

{loadError}

; } if (!customization) { return (

Loading your bit...

); } return (
setCustomization((current) => current ? { ...current, name } : current, ) } />
); }