diff --git a/app/components/agent.tsx b/app/components/agent.tsx new file mode 100644 index 0000000..8a026b4 --- /dev/null +++ b/app/components/agent.tsx @@ -0,0 +1,3 @@ +export function Agent({side}: {side: "T" | "CT"}) { + return <>{side} +} \ No newline at end of file diff --git a/app/components/inventory.tsx b/app/components/inventory.tsx new file mode 100644 index 0000000..b0cca8f --- /dev/null +++ b/app/components/inventory.tsx @@ -0,0 +1,132 @@ +import { useEffect, useState } from "react"; +import { Skeleton, Surface } from "@heroui/react"; +import { Agent } from "./agent"; +import { Weapon } from "./weapon"; +import { useNotification } from "~/hooks/notification"; + +export function Inventory({ side }: { side: "T" | "CT" }) { + const [loading, setLoading] = useState(true); + const [agent, setAgent] = useState({}); + const [gloves, setGloves] = useState({ name: "", color: "", paint_index: 0 }); + const [knife, setKnife] = useState({ name: "", color: "", paint_index: 0 }); + const [weapons, setWeapons] = useState([]); + const { notify } = useNotification(); + + useEffect(() => { + const fetch_weapons = async () => { + let response = await fetch( + `${import.meta.env.VITE_BASE_API_URL}/knife?team=${side}`, + { credentials: "include" }, + ) + .then((r) => r.json()) + .catch((e) => { + notify( + { + type: "danger", + loading: false, + title: "An error occured.", + message: `An error occured: ${e}`, + }, + 10000, + ); + }); + + setKnife(response); + + response = await fetch( + `${import.meta.env.VITE_BASE_API_URL}/gloves?team=${side}`, + { credentials: "include" }, + ) + .then((r) => r.json()) + .catch((e) => { + notify( + { + type: "danger", + loading: false, + title: "An error occured.", + message: `An error occured: ${e}`, + }, + 10000, + ); + }); + + setGloves(response) + setLoading(false); + }; + + if (loading) fetch_weapons(); + }, [loading]); + + useEffect(() => { + setLoading(true); + }, [side]); + + if (loading) { + return ( +
+ + +
+ + + +
+
+ +
+ {Array.from({ length: 50 }, (_, index) => ( + + ))} +
+
+
+ ); + } else { + return ( +
+ + +
+ + + +
+
+ +
+ {Array.from({ length: 50 }, (_, index) => ( + + ))} +
+
+
+ ); + } +} diff --git a/app/components/weapon.tsx b/app/components/weapon.tsx new file mode 100644 index 0000000..1257bb1 --- /dev/null +++ b/app/components/weapon.tsx @@ -0,0 +1,24 @@ +import { Button } from "@heroui/react"; + +export function Weapon({ + weapon_id, + color, + paint_index = 0, +}: { + weapon_id: string; + color: string; + paint_index?: number; +}) { + const acolor = `${color}64` + return ( + + ); +} diff --git a/app/pages/inventory.tsx b/app/pages/inventory.tsx index 9f88ae1..28ec544 100644 --- a/app/pages/inventory.tsx +++ b/app/pages/inventory.tsx @@ -1,5 +1,48 @@ +import { useState } from "react"; import Base from "./base"; +import { Surface, Tabs } from "@heroui/react"; +import { Inventory } from "~/components/inventory"; export function InventoryPage() { - return INVENTORY; + const [side, setSide] = useState<"T" | "CT">("T"); + return ( + + +
+ { + switch (key) { + case "T": { + setSide("T"); + break; + } + case "CT": { + setSide("CT"); + break; + } + } + }} + > + + + + Terrorist + + + + Counter-Terrorist + + + + + +
+ +
+ + ); }