diff --git a/panel/src/pages/PlayerDashboard.tsx b/panel/src/pages/PlayerDashboard.tsx index ecfdfe1..8d915d8 100644 --- a/panel/src/pages/PlayerDashboard.tsx +++ b/panel/src/pages/PlayerDashboard.tsx @@ -11,33 +11,41 @@ interface UserData { className: string | null; } -interface InventoryItem { - itemId: string; - name: string; - quantity: number; - rarity: string; +interface InventoryEntry { + itemId: number; + quantity: string; + item: { + name: string; + rarity: string; + }; } export default function PlayerDashboard({ userId }: { userId: string }) { const [user, setUser] = useState(null); - const [inventory, setInventory] = useState([]); + const [inventory, setInventory] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [inventoryError, setInventoryError] = useState(false); useEffect(() => { async function load() { try { - const [userData, invData] = await Promise.all([ - get(`/api/users/${userId}`), - get<{ items: InventoryItem[] }>(`/api/users/${userId}/inventory`).catch(() => ({ items: [] })), - ]); + const userData = await get(`/api/users/${userId}`); setUser(userData); - setInventory(invData.items ?? []); - } catch (e) { + } catch { setError("Failed to load profile"); - } finally { setLoading(false); + return; } + + try { + const data = await get<{ inventory: InventoryEntry[] }>(`/api/users/${userId}/inventory`); + setInventory(data.inventory ?? []); + } catch { + setInventoryError(true); + } + + setLoading(false); } load(); }, [userId]); @@ -66,7 +74,7 @@ export default function PlayerDashboard({ userId }: { userId: string }) { - +
@@ -74,19 +82,21 @@ export default function PlayerDashboard({ userId }: { userId: string }) { Inventory ({inventory.length})
- {inventory.length === 0 ? ( + {inventoryError ? ( +
Failed to load inventory
+ ) : inventory.length === 0 ? (
No items yet
) : (
- {inventory.slice(0, 10).map((item, i) => ( -
-
{item.name}
+ {inventory.slice(0, 10).map((entry) => ( +
+
{entry.item.name}
- - {item.rarity} + + {entry.item.rarity} - {item.quantity > 1 && ( - x{item.quantity} + {Number(entry.quantity) > 1 && ( + x{entry.quantity} )}