Files
HaBit/components/avatar/avatar-page-content.tsx
Harkamal Randhawa 3be729327b Add inline pet rename, larger header text, and HaBit branding.
Let users edit the pet name from PetHabitat with a pencil icon, bump the name and mood header sizing, and rename user-facing Habit Pet copy to HaBit Pet.
2026-05-24 08:47:48 -06:00

58 lines
1.4 KiB
TypeScript

"use client";
import { useCallback, useEffect, useState } from "react";
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<AvatarCustomization | null>(
null,
);
const [loadError, setLoadError] = useState<string | null>(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]);
if (loadError) {
return <p className="text-xs text-red-500">{loadError}</p>;
}
if (!customization) {
return (
<p className="text-xs text-muted-foreground">Loading your pet...</p>
);
}
return (
<PetHabitat
customization={customization}
fillViewport
onNameChange={(name) =>
setCustomization((current) => ({ ...current, name }))
}
/>
);
}