From 4a7dae218b18327b6f720ef343ab49bd8cf824db Mon Sep 17 00:00:00 2001 From: Polaris Date: Mon, 26 Aug 2024 15:03:50 -0400 Subject: [PATCH] fixed version selection default value and added proper avatar names to the dropdown preview --- .../versions/gameSelection.tsx | 23 +++++-- app/(sharing)/[token]/token.ts | 1 - .../avatarcustomization/page.tsx | 67 ++++++++++--------- .../mapiconcustomization/page.tsx | 10 +-- .../nameplatecustomization/page.tsx | 5 +- .../systemvoicecustomization/page.tsx | 5 +- .../trophycustomization/page.tsx | 5 +- 7 files changed, 68 insertions(+), 48 deletions(-) diff --git a/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx b/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx index e416134..87f9ee4 100644 --- a/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx +++ b/app/(authenticated)/(settings)/settings/(settings components)/versions/gameSelection.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { FC, useState } from "react"; +import React, { FC, useEffect, useState } from "react"; import { Check, ChevronsUpDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; @@ -29,7 +29,7 @@ import { PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; -import { updatePlayerGameVersionChuni } from "./actions"; +import { getGameList, updatePlayerGameVersionChuni } from "./actions"; type ChunithmGameVersionSelectionProps = { chunithmGameVersionNumber: { @@ -48,12 +48,25 @@ export function PlayerChangableChunithmGameVersionSelection({}: ChunithmGameVers const [selectedGameVersion, setSelectedGameVersion] = useState< string | undefined - >(Object.values(GameVersion)[0]); + >(undefined); + + useEffect(() => { + async function fetchCurrentGameVersion() { + try { + const gameList = await getGameList(); + const currentVersion = gameList[0]?.gameVersion; + setSelectedGameVersion(currentVersion); + form.setValue("gameVersion", currentVersion); + } catch (error) { + console.error("Error fetching current game version:", error); + } + } + fetchCurrentGameVersion(); + }, []); + function onSubmit(data: z.infer) { const newGameVersion = data.gameVersion ?? selectedGameVersion; - // console.log("Submitted Game Version:", newGameVersion); - updatePlayerGameVersionChuni(newGameVersion as GameVersion) .then((result) => { toast({ diff --git a/app/(sharing)/[token]/token.ts b/app/(sharing)/[token]/token.ts index 9696b4e..2848dd6 100644 --- a/app/(sharing)/[token]/token.ts +++ b/app/(sharing)/[token]/token.ts @@ -4,7 +4,6 @@ import { getAuth } from "@/auth/queries/getauth"; import { daphnis } from "@/lib/prisma"; import { randomUUID } from "crypto"; import { randomBytes } from "crypto"; -import { redirect } from "next/navigation"; export async function generateShareToken(id: number): Promise<{ token?: string; diff --git a/components/(customization)/avatarcustomization/page.tsx b/components/(customization)/avatarcustomization/page.tsx index e16fbd3..31576b0 100644 --- a/components/(customization)/avatarcustomization/page.tsx +++ b/components/(customization)/avatarcustomization/page.tsx @@ -56,7 +56,6 @@ type AvatarSelectionProps = { avatarParts: chunithm_avatar[]; }; }; - export const AvatarCustomization: FC = ({ avatarHeadSelectionData, avatarFaceSelectionData, @@ -79,7 +78,6 @@ export const AvatarCustomization: FC = ({ const [avatarFaceId, setAvatarFaceId] = useState( undefined, ); - const [avatarSkinId, setAvatarSkinId] = useState( undefined, ); @@ -99,32 +97,39 @@ export const AvatarCustomization: FC = ({ 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) { - 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) { + 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 = ({ 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 = ({ - + No avatar part found. @@ -336,7 +341,7 @@ export const AvatarCustomization: FC = ({ 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 = ({ - + No avatar part found. @@ -401,7 +406,7 @@ export const AvatarCustomization: FC = ({ 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 = ({ - + No avatar part found. @@ -466,7 +471,7 @@ export const AvatarCustomization: FC = ({ 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 = ({ - + No avatar part found. @@ -531,7 +536,7 @@ export const AvatarCustomization: FC = ({ 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 = ({ - + No avatar part found. diff --git a/components/(customization)/mapiconcustomization/page.tsx b/components/(customization)/mapiconcustomization/page.tsx index 6d76182..f525f86 100644 --- a/components/(customization)/mapiconcustomization/page.tsx +++ b/components/(customization)/mapiconcustomization/page.tsx @@ -50,7 +50,7 @@ export const MapIconCustomization: FC = ({ }) => { const FormSchema = z.object({ mapIconId: z.number({ - required_error: "Please select an Avatar Head Item.", + required_error: "Please select an Map Icon.", }), }); @@ -59,13 +59,13 @@ export const MapIconCustomization: FC = ({ }); const [mapIconId, setMapIconId] = useState(undefined); - useEffect(() => { const fetchMapIcons = async () => { try { const data = await getCurrentMapIcon(); if (data.length > 0) { - setMapIconId(data[0].mapIconId!); + setMapIconId(data[0].mapIconId ?? undefined); // Handle null as undefined + form.setValue("mapIconId", data[0].mapIconId as number); } } catch (error) { console.error("Error fetching avatar parts:", error); @@ -146,7 +146,7 @@ export const MapIconCustomization: FC = ({ variant="outline" role="combobox" className={cn( - "w-[300px] justify-between", + "w-[400px] justify-between", !field.value && "text-muted-foreground", )} > @@ -159,7 +159,7 @@ export const MapIconCustomization: FC = ({ - + No name plate found. diff --git a/components/(customization)/nameplatecustomization/page.tsx b/components/(customization)/nameplatecustomization/page.tsx index 2fbbda4..56a8e89 100644 --- a/components/(customization)/nameplatecustomization/page.tsx +++ b/components/(customization)/nameplatecustomization/page.tsx @@ -67,6 +67,7 @@ export const NameplateCustomization: FC = ({ const data = await getCurrentNameplate(); if (data.length > 0) { setNameplateId(data[0].nameplateId!); + form.setValue("nameplateId", data[0].nameplateId as number); } } catch (error) { console.error("Error fetching avatar parts:", error); @@ -141,7 +142,7 @@ export const NameplateCustomization: FC = ({ variant="outline" role="combobox" className={cn( - "w-[300px] justify-between", + "w-[400px] justify-between", !field.value && "text-muted-foreground", )} > @@ -154,7 +155,7 @@ export const NameplateCustomization: FC = ({ - + No name plate found. diff --git a/components/(customization)/systemvoicecustomization/page.tsx b/components/(customization)/systemvoicecustomization/page.tsx index c745b06..242daac 100644 --- a/components/(customization)/systemvoicecustomization/page.tsx +++ b/components/(customization)/systemvoicecustomization/page.tsx @@ -75,6 +75,7 @@ export const SystemVoiceCustomization: FC = ({ const data = await getCurrentSystemVoice(); if (data.length > 0) { setSytemVoiceId(data[0].voiceId!); + form.setValue("PlayerSystemVoice", data[0].voiceId as number); } } catch (error) { console.error("Error fetching system voices:", error); @@ -152,7 +153,7 @@ export const SystemVoiceCustomization: FC = ({ variant="outline" role="combobox" className={cn( - "w-[300px] justify-between", + "w-[400px] justify-between", !field.value && "text-muted-foreground", )} > @@ -165,7 +166,7 @@ export const SystemVoiceCustomization: FC = ({ - + No system voice found. diff --git a/components/(customization)/trophycustomization/page.tsx b/components/(customization)/trophycustomization/page.tsx index 2cceaa5..2b2accd 100644 --- a/components/(customization)/trophycustomization/page.tsx +++ b/components/(customization)/trophycustomization/page.tsx @@ -66,6 +66,7 @@ export const TrophyCustomization: FC = ({ const data = await getCurrentTrophies(); if (data.length > 0) { setTrophyId(data[0].trophyId!); + form.setValue("trophies", data[0].trophyId as number); } } catch (error) { console.error("Error fetching avatar parts:", error); @@ -118,7 +119,7 @@ export const TrophyCustomization: FC = ({ variant="outline" role="combobox" className={cn( - "w-[300px] justify-between", + "w-[400px] justify-between", !field.value && "text-muted-foreground", )} > @@ -131,7 +132,7 @@ export const TrophyCustomization: FC = ({ - + No avatar part found.