fixed version selection default value and added proper avatar names to the dropdown preview

This commit is contained in:
Polaris
2024-08-26 15:03:50 -04:00
parent 90ae8fc48c
commit 4a7dae218b
7 changed files with 68 additions and 48 deletions

View File

@ -56,7 +56,6 @@ type AvatarSelectionProps = {
avatarParts: chunithm_avatar[];
};
};
export const AvatarCustomization: FC<AvatarSelectionProps> = ({
avatarHeadSelectionData,
avatarFaceSelectionData,
@ -79,7 +78,6 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
const [avatarFaceId, setAvatarFaceId] = useState<number | undefined>(
undefined,
);
const [avatarSkinId, setAvatarSkinId] = useState<number | undefined>(
undefined,
);
@ -99,32 +97,39 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
useEffect(() => {
const fetchAvatarParts = async () => {
try {
const data = await getCurrentAvatarParts();
setAvatarFaceId(data[0].avatarFace!);
setAvatarSkinId(data[0].avatarSkin!);
setAvatarHeadId(data[0].avatarHead!);
setAvatarWearId(data[0].avatarWear!);
setAvatarBackId(data[0].avatarBack!);
setAvatarItemId(data[0].avatarItem!);
const avatarData = await getCurrentAvatarParts();
const [currentAvatarParts] = avatarData;
if (currentAvatarParts) {
setAvatarFaceId(currentAvatarParts.avatarFace ?? undefined);
setAvatarSkinId(currentAvatarParts.avatarSkin ?? undefined);
setAvatarHeadId(currentAvatarParts.avatarHead ?? undefined);
setAvatarWearId(currentAvatarParts.avatarWear ?? undefined);
setAvatarBackId(currentAvatarParts.avatarBack ?? undefined);
setAvatarItemId(currentAvatarParts.avatarItem ?? undefined);
// Set initial form values based on fetched data
form.reset({
AvatarHeadAccessory: currentAvatarParts.avatarHead ?? undefined,
AvatarFaceAccessory: currentAvatarParts.avatarFace ?? undefined,
AvatarItemAccessory: currentAvatarParts.avatarItem ?? undefined,
AvatarBackAccessory: currentAvatarParts.avatarBack ?? undefined,
AvatarWearAccessory: currentAvatarParts.avatarWear ?? undefined,
});
}
} catch (error) {
console.error("Error fetching avatar parts:", error);
}
};
fetchAvatarParts();
}, []);
function onSubmit(data: z.infer<typeof FormSchema>) {
const defaultHeadId = avatarHeadId;
const defaultFaceId = avatarFaceId;
const defaultBackId = avatarBackId;
const defaultWearId = avatarWearId;
const defaultItemId = avatarItemId;
}, [form]);
const newHeadId = data.AvatarHeadAccessory ?? defaultHeadId;
const newFaceId = data.AvatarFaceAccessory ?? defaultFaceId;
const newBackId = data.AvatarBackAccessory ?? defaultBackId;
const newWearId = data.AvatarWearAccessory ?? defaultWearId;
const newItemId = data.AvatarItemAccessory ?? defaultItemId;
function onSubmit(data: z.infer<typeof FormSchema>) {
const newHeadId = data.AvatarHeadAccessory ?? avatarHeadId;
const newFaceId = data.AvatarFaceAccessory ?? avatarFaceId;
const newBackId = data.AvatarBackAccessory ?? avatarBackId;
const newWearId = data.AvatarWearAccessory ?? avatarWearId;
const newItemId = data.AvatarItemAccessory ?? avatarItemId;
updateAvatarParts(newHeadId, newFaceId, newBackId, newWearId, newItemId)
.then(() => {
@ -271,7 +276,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
"w-[400px] justify-between",
!field.value && "text-muted-foreground",
)}
>
@ -285,7 +290,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<PopoverContent className="w-[400px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>
@ -336,7 +341,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
"w-[400px] justify-between",
!field.value && "text-muted-foreground",
)}
>
@ -350,7 +355,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<PopoverContent className="w-[400px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>
@ -401,7 +406,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
"w-[400px] justify-between",
!field.value && "text-muted-foreground",
)}
>
@ -415,7 +420,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<PopoverContent className="w-[400px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>
@ -466,7 +471,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
"w-[400px] justify-between",
!field.value && "text-muted-foreground",
)}
>
@ -480,7 +485,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<PopoverContent className="w-[400px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>
@ -531,7 +536,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
"w-[400px] justify-between",
!field.value && "text-muted-foreground",
)}
>
@ -545,7 +550,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<PopoverContent className="w-[400px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>