From 5742f9dbc3721325a7fb2071ecd2daa221de9b14 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Tue, 2 Apr 2024 16:15:44 +0100 Subject: [PATCH] show stickers on inventory items --- src/components/steam-inventory-item-info.tsx | 21 ++++++++++++ src/content/steamcommunity/bridge/script.ts | 1 + src/lib/steam.ts | 35 ++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/components/steam-inventory-item-info.tsx b/src/components/steam-inventory-item-info.tsx index 9cf38c5..0a2d609 100644 --- a/src/components/steam-inventory-item-info.tsx +++ b/src/components/steam-inventory-item-info.tsx @@ -2,6 +2,7 @@ import { SteamItemSkinportPrice } from "@/components/steam-item-skinport-price"; import type { SelectedSkinportItemPrice } from "@/lib/skinport"; import type { SteamItem } from "@/lib/steam"; import { useEffect } from "react"; +import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip"; export function SteamInventoryItemInfo({ inventoryItem, @@ -50,8 +51,28 @@ export function SteamInventoryItemInfo({ } }; + const renderItemStickers = () => { + if (inventoryItem?.stickers) { + return ( +
+ {inventoryItem.stickers.map(({ image, marketHashName }) => ( +
+ + + {marketHashName} + + {marketHashName} + +
+ ))} +
+ ); + } + }; + return ( <> + {renderItemStickers()}
{renderItemQuality()} [\w]+: (.+)<\/center>/)?.[1] + .split(","); + + if ( + images && + marketHashNames && + images.length === marketHashNames.length + ) { + stickers = []; + + for (let i = 0; i < images.length; i++) { + stickers.push({ + image: images[i], + marketHashName: marketHashNames[i].trim(), + }); + } + } + } + } + } + return { appId: appid, assetId, @@ -126,6 +160,7 @@ export function parseSteamItem({ qualityColor: qualityTag?.color ? `#${qualityTag.color}` : null, rarity: rarityTag?.internal_name || null, rarityColor: rarityTag?.color ? `#${rarityTag.color}` : null, + stickers, }; }