diff --git a/app/components/inventory.tsx b/app/components/inventory.tsx index b0c181d..f1f5b34 100644 --- a/app/components/inventory.tsx +++ b/app/components/inventory.tsx @@ -1,25 +1,16 @@ import { useEffect, useState } from "react"; import { Skeleton, Surface } from "@heroui/react"; import { Agent } from "./agent"; -import { Weapon } from "./weapon"; +import { SkinTile } from "./skin_tile"; import { useNotification } from "~/hooks/notification"; - -interface SkinInfo { - id: string; - name: string; - color: string; - display: string; - paint_index: number; - float: number; - pattern: number; -} +import { WeaponInfo, AgentInfo } from "~/types/skin"; export function Inventory({ side }: { side: "T" | "CT" }) { const [loading, setLoading] = useState(true); - const [agent, setAgent] = useState(); - const [gloves, setGloves] = useState(); - const [knife, setKnife] = useState(); - const [weapons, setWeapons] = useState>([]); + const [agent, setAgent] = useState(); + const [gloves, setGloves] = useState(); + const [knife, setKnife] = useState(); + const [weapons, setWeapons] = useState>([]); const { notify } = useNotification(); useEffect(() => { @@ -41,7 +32,7 @@ export function Inventory({ side }: { side: "T" | "CT" }) { ); }); - setKnife(response[0]); + setKnife(new WeaponInfo(response[0])); response = await fetch( `${import.meta.env.VITE_BASE_API_URL}/skin?team=${side}&category=Gloves`, @@ -60,7 +51,7 @@ export function Inventory({ side }: { side: "T" | "CT" }) { ); }); - setGloves(response[0]); + setGloves(new WeaponInfo(response[0])); response = await fetch( `${import.meta.env.VITE_BASE_API_URL}/skin?team=${side}`, @@ -79,7 +70,7 @@ export function Inventory({ side }: { side: "T" | "CT" }) { ); }); - setWeapons(response); + setWeapons(response.map((item: any) => (new WeaponInfo(item)))); response = await fetch( `${import.meta.env.VITE_BASE_API_URL}/agent?team=${side}`, @@ -98,7 +89,7 @@ export function Inventory({ side }: { side: "T" | "CT" }) { ); }); - setAgent(response); + setAgent(new AgentInfo(response)); setLoading(false); }; @@ -149,31 +140,19 @@ export function Inventory({ side }: { side: "T" | "CT" }) { {agent && }
{knife && ( - + )} {gloves && ( - + )} {agent && ( - + )}
@@ -183,14 +162,9 @@ export function Inventory({ side }: { side: "T" | "CT" }) { >
{weapons.map((v, i) => ( - ))}
diff --git a/app/components/skin_tile.tsx b/app/components/skin_tile.tsx new file mode 100644 index 0000000..e312299 --- /dev/null +++ b/app/components/skin_tile.tsx @@ -0,0 +1,58 @@ +import { Button, Typography } from "@heroui/react"; +import { Float } from "./float"; +import { useState } from "react"; +import { SkinDialog } from "./skin_dialog"; +import { WeaponInfo, AgentInfo } from "~/types/skin"; + +export function SkinTile({ skin }: { skin: WeaponInfo | AgentInfo }) { + const [isDialogOpen, setIsDialogOpen] = useState(false); + const acolor = `${skin.color}64`; + return ( + <> + + + + ); +} diff --git a/app/components/weapon.tsx b/app/components/weapon.tsx deleted file mode 100644 index a074510..0000000 --- a/app/components/weapon.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { Button, Surface, Typography } from "@heroui/react"; -import { Float } from "./float"; - -export function Weapon({ - weapon_id, - color, - display = "Weapon", - float, - pattern, - paint_index = 0, -}: { - weapon_id: string; - color: string; - display?: string; - float?: number; - pattern?: number; - paint_index?: number; -}) { - const acolor = `${color}64`; - return ( - - ); -} diff --git a/app/types/skin.ts b/app/types/skin.ts new file mode 100644 index 0000000..0e02d34 --- /dev/null +++ b/app/types/skin.ts @@ -0,0 +1,24 @@ +export class WeaponInfo { + id!: string; + name!: string; + color!: string; + display!: string; + paint_index!: number; + float!: number; + pattern!: number; + + constructor(data: WeaponInfo) { + Object.assign(this, data); + } +} + +export class AgentInfo { + id!: string; + name!: string; + color!: string; + display!: string; + + constructor(data: AgentInfo) { + Object.assign(this, data); + } +} \ No newline at end of file