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 ( +