diff --git a/app/(authenticated)/chunithm/page.tsx b/app/(authenticated)/chunithm/page.tsx index 7f9c446..7ba51b0 100644 --- a/app/(authenticated)/chunithm/page.tsx +++ b/app/(authenticated)/chunithm/page.tsx @@ -1,8 +1,22 @@ -import { AvatarCustomization } from "@/components/avatarcustomization/page"; -import ChunithmScorePlaylog from "@/components/scoreplaylog/page"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +"use server"; + +import React from "react"; +import { getAllAvatarParts } from "@/lib/api"; +import { AvatarCustomization } from "@/components/avatarcustomization/page"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import ChunithmScorePlaylog from "@/components/scoreplaylog/page"; + +const getAvatarParts = async () => { + console.log("Executed on the server side"); + + const avatarParts = await getAllAvatarParts(); + return { avatarParts }; +}; + +const Page = async () => { + console.log("Executed on the server side"); + const avatarPartsData = await getAvatarParts(); -const ChunithmPage = () => { return (
@@ -15,7 +29,7 @@ const ChunithmPage = () => {
- +
@@ -23,4 +37,4 @@ const ChunithmPage = () => { ); }; -export default ChunithmPage; +export default Page; diff --git a/components/avatarcustomization/page.tsx b/components/avatarcustomization/page.tsx index 7e3971e..6ad2222 100644 --- a/components/avatarcustomization/page.tsx +++ b/components/avatarcustomization/page.tsx @@ -1,5 +1,424 @@ -import React from "react"; +"use client"; -export const AvatarCustomization = () => { - return
AvatarCustomization
; +import React, { FC, useEffect, useState } from "react"; +import { chuni_static_avatar } from "@/prisma/schemas/artemis/generated/artemis"; +import { Check, ChevronsUpDown } from "lucide-react"; + +import { cn } from "@/lib/utils"; +import { Button } from "@/components/ui/button"; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "@/components/ui/command"; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import { z } from "zod"; +type chunithm_avatar = chuni_static_avatar; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { toast } from "../ui/use-toast"; + +type AvatarSelectionProps = { + avatarSelectionData: { + avatarParts: chunithm_avatar[]; + }; }; + +export const AvatarCustomization: FC = ({ + avatarSelectionData, +}) => { + const FormSchema = z.object({ + AvatarHeadAccessory: z.number({ + required_error: "Please select a language.", + }), + AvatarFaceAccessory: z.number({ + required_error: "Please select a language.", + }), + AvatarItemAccessory: z.number({ + required_error: "Please select a language.", + }), + AvatarBackAccessory: z.number({ + required_error: "Please select a language.", + }), + AvatarWearAccessory: z.number({ + required_error: "Please select a language.", + }), + }); + + const form = useForm>({ + resolver: zodResolver(FormSchema), + }); + + function onSubmit(data: z.infer) { + toast({ + title: "You submitted the following values:", + description: ( +
+          {JSON.stringify(data, null, 2)}
+        
+ ), + }); + } + + return ( +
+
+ + ( + + Avatar Head Item + + + + + + + + + {/* bugged */} + {/* */} + + No language found. + + {avatarSelectionData.avatarParts.map((part) => ( + { + form.setValue( + "AvatarHeadAccessory", + part.avatarAccessoryId! + ); + }} + > + + {part.name} + + ))} + + + + + + + + + )} + /> + ( + + Avatar Face Item + + + + + + + + + {/* bugged */} + {/* */} + + No language found. + + {avatarSelectionData.avatarParts.map((part) => ( + { + form.setValue( + "AvatarFaceAccessory", + part.avatarAccessoryId! + ); + }} + > + + {part.name} + + ))} + + + + + + + + + )} + /> + ( + + Avatar Hand Item + + + + + + + + + {/* bugged */} + {/* */} + + No language found. + + {avatarSelectionData.avatarParts.map((part) => ( + { + form.setValue( + "AvatarItemAccessory", + part.avatarAccessoryId! + ); + }} + > + + {part.name} + + ))} + + + + + + + + + )} + /> + ( + + Avatar Back Item + + + + + + + + + {/* bugged */} + {/* */} + + No language found. + + {avatarSelectionData.avatarParts.map((part) => ( + { + form.setValue( + "AvatarBackAccessory", + part.avatarAccessoryId! + ); + }} + > + + {part.name} + + ))} + + + + + + + + + )} + /> + ( + + Avatar Body Item + + + + + + + + + {/* bugged */} + {/* */} + + No language found. + + {avatarSelectionData.avatarParts.map((part) => ( + { + form.setValue( + "AvatarWearAccessory", + part.avatarAccessoryId! + ); + }} + > + + {part.name} + + ))} + + + + + + + + + )} + /> + + + +
+ ); +}; + +{ + /*
State is: {state}
+
Server data:
+
+
    + {avatarSelectionData.avatarParts.map((part) => ( +
  • {part.name}
  • + ))} +
*/ +} diff --git a/lib/api.ts b/lib/api.ts index ac9ee9b..a8f5153 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -181,7 +181,7 @@ export async function getAllAimeCards() { } -export async function getAvatarPart() { +export async function getAllAvatarParts() { const { user } = await getAuth(); if (!user || !user.accessCode) { @@ -193,6 +193,7 @@ export async function getAvatarPart() { category: 1 }, select: { + id: true, name: true, avatarAccessoryId: true, category: true,