From 788fcc9a5d84ea39a0b1a303cb90b93960ae1206 Mon Sep 17 00:00:00 2001 From: 8liam Date: Sun, 22 Nov 2026 21:07:18 +1000 Subject: [PATCH 1/2] feat(inventory): show attached charm value separately from item price - Sum priced charms attached to weapons into a charms value, shown as "+ X" on grid cards and table price cells - Add a Charms stat to the portfolio hero; excluded from total value so loose charms are not double counted - routeTree.gen.ts has formatter-only churn (quotes, semicolons) from regeneration --- server/dashboard.test.ts | 15 ++ server/dashboard.ts | 3 + .../item-grid-card.component.tsx | 8 + .../item-grid-card/item-grid-card.config.ts | 1 + .../item-table/item-table.component.tsx | 19 +- .../item-table/item-table.config.ts | 1 + .../portfolio-hero.component.tsx | 9 + src/lib/copy/copy.config.ts | 6 + src/lib/items/charm-value.test.ts | 45 ++++ src/lib/items/charm-value.ts | 18 ++ src/lib/items/dashboard.types.ts | 2 + src/routeTree.gen.ts | 254 ++++++++++-------- 12 files changed, 264 insertions(+), 117 deletions(-) create mode 100644 src/lib/items/charm-value.test.ts create mode 100644 src/lib/items/charm-value.ts diff --git a/server/dashboard.test.ts b/server/dashboard.test.ts index 41f60064..d60c2ca2 100644 --- a/server/dashboard.test.ts +++ b/server/dashboard.test.ts @@ -231,3 +231,18 @@ test("an account that starts reporting later adds to the total from then on", () [10, 10, 100], ); }); + +test("charm value is reported on its own and never added to the total", () => { + const charm = { name: "Charm", imageUrl: null, pattern: null, videoUrl: null }; + const dash = build([ + item("a", { charms: [{ ...charm, marketHashName: "Charm | A", price: 4 }] }), + item("b", { + charms: [ + { ...charm, marketHashName: "Charm | B", price: 1.5 }, + { ...charm, marketHashName: "Charm | C", price: null }, + ], + }), + ]); + assert.equal(dash.totals.charmsValue, 5.5); + assert.equal(dash.totals.value, 20); +}); diff --git a/server/dashboard.ts b/server/dashboard.ts index 5f32177d..903eca28 100644 --- a/server/dashboard.ts +++ b/server/dashboard.ts @@ -7,6 +7,7 @@ import type { ValueChange, } from "../src/lib/items/dashboard.types.ts"; import { itemRowKey } from "../src/lib/items/item-key.ts"; +import { attachedCharmsValue } from "../src/lib/items/charm-value.ts"; import { INVENTORY_LOCATION_ID, type ItemView } from "../src/lib/items/item.types.ts"; import { DASHBOARD } from "../src/lib/storage/storage.config.ts"; import type { ValueSnapshot } from "./db/db.types.ts"; @@ -72,6 +73,7 @@ export function buildDashboard(args: { const { items, history, currency, priceUpdatedAt, unitsLoaded, unitsTotal } = args; const now = args.now ?? Date.now(); const { inventoryValue, storageValue, totalValue } = summarizeValue(items); + const charmsValue = items.reduce((sum, item) => sum + (attachedCharmsValue(item) ?? 0), 0); const category = new Map(); const rarity = new Map(); @@ -153,6 +155,7 @@ export function buildDashboard(args: { itemCount: items.length, inventoryValue, storageValue, + charmsValue, unitsLoaded, unitsTotal, }, diff --git a/src/components/item-grid-card/item-grid-card.component.tsx b/src/components/item-grid-card/item-grid-card.component.tsx index 45aa4a47..a129a654 100644 --- a/src/components/item-grid-card/item-grid-card.component.tsx +++ b/src/components/item-grid-card/item-grid-card.component.tsx @@ -10,6 +10,7 @@ import { } from "~/components/item-highlights/item-highlights.component"; import { splitItemName } from "~/components/item-label/item-label.utils"; import { charmTooltipDetail } from "~/lib/items/charm-tooltip"; +import { attachedCharmsValue } from "~/lib/items/charm-value"; import { COPY } from "~/lib/copy/copy.config"; import { cn } from "~/utils/cn"; import { formatFloat, formatMoney } from "~/utils/format"; @@ -40,6 +41,7 @@ export function ItemGridCard({ const stickers = item.stickers.filter((sticker) => sticker.imageUrl !== null); const hiddenStickers = stickers.length - maxStickers; const hasAttachments = stickers.length > 0 || item.charms.length > 0; + const charmsValue = attachedCharmsValue(item); const charmVideos = item.charms.filter((charm) => charm.videoUrl !== null); const hasChips = charmVideos.length > 0 || item.videoUrl !== null; const hasFooter = hasAttachments || hasChips || showLocation; @@ -100,6 +102,12 @@ export function ItemGridCard({

{item.price === null ? COPY.common.empty : formatMoney(item.price, currency)}

+ {charmsValue !== null && ( +

+ {COPY.itemGridCard.charmsValuePrefix} + {formatMoney(charmsValue, currency)} +

+ )} {status !== null && (

r.price, - cell: (r) => (r.price === null ? COPY.common.empty : formatMoney(r.price, currency)), + cell: (r) => { + const charmsValue = attachedCharmsValue(r); + return ( + <> + {r.price === null ? COPY.common.empty : formatMoney(r.price, currency)} + {charmsValue !== null && ( + + {COPY.itemGridCard.charmsValuePrefix} + {formatMoney(charmsValue, currency)} + + )} + + ); + }, }; const location: DataTableColumn[] = showLocation ? [ diff --git a/src/components/item-table/item-table.config.ts b/src/components/item-table/item-table.config.ts index ae683fe0..2b37c58d 100644 --- a/src/components/item-table/item-table.config.ts +++ b/src/components/item-table/item-table.config.ts @@ -38,6 +38,7 @@ export const ITEM_TABLE = { direction, })) satisfies readonly DataTableSortOption[], sortLabel: ITEM_SORT_LABEL, + charmsValueClass: "block text-xs font-normal text-muted-foreground", initialSort: { columnId: "price", direction: "desc" } satisfies SortState, /** Enough rows to fill a tall screen; the rest are clipped. */ skeletonRows: 16, diff --git a/src/components/portfolio-hero/portfolio-hero.component.tsx b/src/components/portfolio-hero/portfolio-hero.component.tsx index 75ebf743..b48135de 100644 --- a/src/components/portfolio-hero/portfolio-hero.component.tsx +++ b/src/components/portfolio-hero/portfolio-hero.component.tsx @@ -17,6 +17,15 @@ export function PortfolioHero({ dashboard, currency }: PortfolioHeroProps) { detail: `${totals.unitsLoaded}/${totals.unitsTotal} units`, }, { label: copy.items, value: formatInteger(totals.itemCount) }, + ...(totals.charmsValue > 0 + ? [ + { + label: copy.charms, + value: formatMoney(totals.charmsValue, currency), + detail: copy.charmsDetail, + }, + ] + : []), ]; return (

diff --git a/src/lib/copy/copy.config.ts b/src/lib/copy/copy.config.ts index 64b88977..e5f8f677 100644 --- a/src/lib/copy/copy.config.ts +++ b/src/lib/copy/copy.config.ts @@ -170,6 +170,10 @@ export const COPY = { scope: (label: string) => `Covers: ${label}`, ariaFor: (label: string) => `Refresh ${label}`, }, + itemGridCard: { + charmsValuePrefix: "+ ", + charmsValueTitle: "Market value of the attached charms, not included in the price", + }, itemColumns: { item: "Item", location: "Location", @@ -185,6 +189,8 @@ export const COPY = { inventory: "Inventory", storage: "Storage units", items: "Items", + charms: "Charms", + charmsDetail: "not in total", change: { day: "24h", week: "7d", month: "30d" }, historyTitle: "Value over time", historyEmpty: diff --git a/src/lib/items/charm-value.test.ts b/src/lib/items/charm-value.test.ts new file mode 100644 index 00000000..89901ff2 --- /dev/null +++ b/src/lib/items/charm-value.test.ts @@ -0,0 +1,45 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { attachedCharmsValue } from "./charm-value.ts"; +import type { CharmView } from "./item.types.ts"; + +const charm = (over: Partial): CharmView => ({ + name: "Charm | Lil' Ava", + imageUrl: null, + pattern: null, + videoUrl: null, + marketHashName: "Charm | Lil' Ava", + price: null, + ...over, +}); + +describe("attachedCharmsValue", () => { + it("is null when the weapon has no charms", () => { + assert.equal(attachedCharmsValue({ charms: [], marketHashName: "AK-47 | Redline" }), null); + }); + it("is null when no charm is priced", () => { + assert.equal( + attachedCharmsValue({ charms: [charm({})], marketHashName: "AK-47 | Redline" }), + null, + ); + }); + it("sums priced charms and ignores unpriced ones", () => { + assert.equal( + attachedCharmsValue({ + charms: [charm({ price: 12.5 }), charm({ price: null }), charm({ price: 3 })], + marketHashName: "AK-47 | Redline", + }), + 15.5, + ); + }); + it("does not count a loose charm twice", () => { + assert.equal( + attachedCharmsValue({ + charms: [charm({ price: 9 })], + marketHashName: "Charm | Lil' Ava", + }), + null, + ); + }); +}); diff --git a/src/lib/items/charm-value.ts b/src/lib/items/charm-value.ts new file mode 100644 index 00000000..66f90812 --- /dev/null +++ b/src/lib/items/charm-value.ts @@ -0,0 +1,18 @@ +import type { ItemView } from "./item.types.ts"; + +/** + * Combined market value of the charms attached to a weapon, or null when none is priced. + * A loose charm lists itself in `charms`, and its own price already covers it, so it is skipped. + */ +export function attachedCharmsValue( + item: Pick, +): number | null { + let total = 0; + let priced = false; + for (const charm of item.charms) { + if (charm.price === null || charm.marketHashName === item.marketHashName) continue; + total += charm.price; + priced = true; + } + return priced ? total : null; +} diff --git a/src/lib/items/dashboard.types.ts b/src/lib/items/dashboard.types.ts index 4d78f45f..1ea70252 100644 --- a/src/lib/items/dashboard.types.ts +++ b/src/lib/items/dashboard.types.ts @@ -53,6 +53,8 @@ export type Dashboard = { readonly itemCount: number; readonly inventoryValue: number; readonly storageValue: number; + /** Market value of charms attached to weapons; already excluded from `value`. */ + readonly charmsValue: number; readonly unitsLoaded: number; readonly unitsTotal: number; }; diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 7673f762..b5373ab6 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -8,148 +8,170 @@ // You should NOT make any changes in this file as it will be overwritten. // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. -import { Route as rootRouteImport } from "./routes/__root"; -import { Route as IndexRouteImport } from "./routes/index"; -import { Route as CasesRouteImport } from "./routes/cases"; -import { Route as ItemsRouteImport } from "./routes/items"; -import { Route as SettingsRouteImport } from "./routes/settings"; -import { Route as StorageRouteImport } from "./routes/storage"; -import { Route as TerminalsRouteImport } from "./routes/terminals"; -import { Route as TradeupRouteImport } from "./routes/tradeup"; +import { Route as rootRouteImport } from './routes/__root' +import { Route as IndexRouteImport } from './routes/index' +import { Route as CasesRouteImport } from './routes/cases' +import { Route as ItemsRouteImport } from './routes/items' +import { Route as SettingsRouteImport } from './routes/settings' +import { Route as StorageRouteImport } from './routes/storage' +import { Route as TerminalsRouteImport } from './routes/terminals' +import { Route as TradeupRouteImport } from './routes/tradeup' const IndexRoute = IndexRouteImport.update({ - id: "/", - path: "/", + id: '/', + path: '/', getParentRoute: () => rootRouteImport, -} as any); +} as any) const CasesRoute = CasesRouteImport.update({ - id: "/cases", - path: "/cases", + id: '/cases', + path: '/cases', getParentRoute: () => rootRouteImport, -} as any); +} as any) const ItemsRoute = ItemsRouteImport.update({ - id: "/items", - path: "/items", + id: '/items', + path: '/items', getParentRoute: () => rootRouteImport, -} as any); +} as any) const SettingsRoute = SettingsRouteImport.update({ - id: "/settings", - path: "/settings", + id: '/settings', + path: '/settings', getParentRoute: () => rootRouteImport, -} as any); +} as any) const StorageRoute = StorageRouteImport.update({ - id: "/storage", - path: "/storage", + id: '/storage', + path: '/storage', getParentRoute: () => rootRouteImport, -} as any); +} as any) const TerminalsRoute = TerminalsRouteImport.update({ - id: "/terminals", - path: "/terminals", + id: '/terminals', + path: '/terminals', getParentRoute: () => rootRouteImport, -} as any); +} as any) const TradeupRoute = TradeupRouteImport.update({ - id: "/tradeup", - path: "/tradeup", + id: '/tradeup', + path: '/tradeup', getParentRoute: () => rootRouteImport, -} as any); +} as any) export interface FileRoutesByFullPath { - "/": typeof IndexRoute; - "/cases": typeof CasesRoute; - "/items": typeof ItemsRoute; - "/settings": typeof SettingsRoute; - "/storage": typeof StorageRoute; - "/terminals": typeof TerminalsRoute; - "/tradeup": typeof TradeupRoute; + '/': typeof IndexRoute + '/cases': typeof CasesRoute + '/items': typeof ItemsRoute + '/settings': typeof SettingsRoute + '/storage': typeof StorageRoute + '/terminals': typeof TerminalsRoute + '/tradeup': typeof TradeupRoute } export interface FileRoutesByTo { - "/": typeof IndexRoute; - "/cases": typeof CasesRoute; - "/items": typeof ItemsRoute; - "/settings": typeof SettingsRoute; - "/storage": typeof StorageRoute; - "/terminals": typeof TerminalsRoute; - "/tradeup": typeof TradeupRoute; + '/': typeof IndexRoute + '/cases': typeof CasesRoute + '/items': typeof ItemsRoute + '/settings': typeof SettingsRoute + '/storage': typeof StorageRoute + '/terminals': typeof TerminalsRoute + '/tradeup': typeof TradeupRoute } export interface FileRoutesById { - __root__: typeof rootRouteImport; - "/": typeof IndexRoute; - "/cases": typeof CasesRoute; - "/items": typeof ItemsRoute; - "/settings": typeof SettingsRoute; - "/storage": typeof StorageRoute; - "/terminals": typeof TerminalsRoute; - "/tradeup": typeof TradeupRoute; + __root__: typeof rootRouteImport + '/': typeof IndexRoute + '/cases': typeof CasesRoute + '/items': typeof ItemsRoute + '/settings': typeof SettingsRoute + '/storage': typeof StorageRoute + '/terminals': typeof TerminalsRoute + '/tradeup': typeof TradeupRoute } export interface FileRouteTypes { - fileRoutesByFullPath: FileRoutesByFullPath; - fullPaths: "/" | "/cases" | "/items" | "/settings" | "/storage" | "/terminals" | "/tradeup"; - fileRoutesByTo: FileRoutesByTo; - to: "/" | "/cases" | "/items" | "/settings" | "/storage" | "/terminals" | "/tradeup"; - id: "__root__" | "/" | "/cases" | "/items" | "/settings" | "/storage" | "/terminals" | "/tradeup"; - fileRoutesById: FileRoutesById; + fileRoutesByFullPath: FileRoutesByFullPath + fullPaths: + | '/' + | '/cases' + | '/items' + | '/settings' + | '/storage' + | '/terminals' + | '/tradeup' + fileRoutesByTo: FileRoutesByTo + to: + | '/' + | '/cases' + | '/items' + | '/settings' + | '/storage' + | '/terminals' + | '/tradeup' + id: + | '__root__' + | '/' + | '/cases' + | '/items' + | '/settings' + | '/storage' + | '/terminals' + | '/tradeup' + fileRoutesById: FileRoutesById } export interface RootRouteChildren { - IndexRoute: typeof IndexRoute; - CasesRoute: typeof CasesRoute; - ItemsRoute: typeof ItemsRoute; - SettingsRoute: typeof SettingsRoute; - StorageRoute: typeof StorageRoute; - TerminalsRoute: typeof TerminalsRoute; - TradeupRoute: typeof TradeupRoute; + IndexRoute: typeof IndexRoute + CasesRoute: typeof CasesRoute + ItemsRoute: typeof ItemsRoute + SettingsRoute: typeof SettingsRoute + StorageRoute: typeof StorageRoute + TerminalsRoute: typeof TerminalsRoute + TradeupRoute: typeof TradeupRoute } -declare module "@tanstack/react-router" { +declare module '@tanstack/react-router' { interface FileRoutesByPath { - "/": { - id: "/"; - path: "/"; - fullPath: "/"; - preLoaderRoute: typeof IndexRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/cases": { - id: "/cases"; - path: "/cases"; - fullPath: "/cases"; - preLoaderRoute: typeof CasesRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/items": { - id: "/items"; - path: "/items"; - fullPath: "/items"; - preLoaderRoute: typeof ItemsRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/settings": { - id: "/settings"; - path: "/settings"; - fullPath: "/settings"; - preLoaderRoute: typeof SettingsRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/storage": { - id: "/storage"; - path: "/storage"; - fullPath: "/storage"; - preLoaderRoute: typeof StorageRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/terminals": { - id: "/terminals"; - path: "/terminals"; - fullPath: "/terminals"; - preLoaderRoute: typeof TerminalsRouteImport; - parentRoute: typeof rootRouteImport; - }; - "/tradeup": { - id: "/tradeup"; - path: "/tradeup"; - fullPath: "/tradeup"; - preLoaderRoute: typeof TradeupRouteImport; - parentRoute: typeof rootRouteImport; - }; + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport + parentRoute: typeof rootRouteImport + } + '/cases': { + id: '/cases' + path: '/cases' + fullPath: '/cases' + preLoaderRoute: typeof CasesRouteImport + parentRoute: typeof rootRouteImport + } + '/items': { + id: '/items' + path: '/items' + fullPath: '/items' + preLoaderRoute: typeof ItemsRouteImport + parentRoute: typeof rootRouteImport + } + '/settings': { + id: '/settings' + path: '/settings' + fullPath: '/settings' + preLoaderRoute: typeof SettingsRouteImport + parentRoute: typeof rootRouteImport + } + '/storage': { + id: '/storage' + path: '/storage' + fullPath: '/storage' + preLoaderRoute: typeof StorageRouteImport + parentRoute: typeof rootRouteImport + } + '/terminals': { + id: '/terminals' + path: '/terminals' + fullPath: '/terminals' + preLoaderRoute: typeof TerminalsRouteImport + parentRoute: typeof rootRouteImport + } + '/tradeup': { + id: '/tradeup' + path: '/tradeup' + fullPath: '/tradeup' + preLoaderRoute: typeof TradeupRouteImport + parentRoute: typeof rootRouteImport + } } } @@ -161,7 +183,7 @@ const rootRouteChildren: RootRouteChildren = { StorageRoute: StorageRoute, TerminalsRoute: TerminalsRoute, TradeupRoute: TradeupRoute, -}; +} export const routeTree = rootRouteImport ._addFileChildren(rootRouteChildren) - ._addFileTypes(); + ._addFileTypes() From b4170d3a38b36d0d16a94ff9dd6b191ae9e492ea Mon Sep 17 00:00:00 2001 From: 8liam Date: Sun, 22 Nov 2026 21:14:00 +1000 Subject: [PATCH 2/2] fix(site): add charmsValue to dashboard mock and document site checks --- AGENTS.md | 20 ++++++++++++++++++++ CLAUDE.md | 1 + site/src/mock/data/dashboard.mock.ts | 1 + 3 files changed, 22 insertions(+) create mode 100644 AGENTS.md create mode 100644 CLAUDE.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..74fe87e1 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,20 @@ +# Repository rules + +## Before you push + +The landing site in `site/` imports the real app UI and types from `src/` and `server/` +(see `.github/workflows/site.yml`). A change to a shared type, a prop, or a copy key can break +the site even when the app is green, so run both sets of checks before pushing: + +```sh +# app +vp check && pnpm test && pnpm build + +# site (separate lockfile, install first in a fresh worktree) +cd site && pnpm install --frozen-lockfile && pnpm typecheck && pnpm build +``` + +- Adding a required field to a type from `src/lib/**/*.types.ts` (for example `Dashboard`, + `ItemView`): grep `site/src/mock/` for the type and update every mock that builds it. +- Don't skip `pnpm typecheck` in `site/` because the change looks app-only. That is exactly + how the site CI fails. diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..43c994c2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/site/src/mock/data/dashboard.mock.ts b/site/src/mock/data/dashboard.mock.ts index acff0ea0..3f98b1ac 100644 --- a/site/src/mock/data/dashboard.mock.ts +++ b/site/src/mock/data/dashboard.mock.ts @@ -75,6 +75,7 @@ export const DASHBOARD_MOCK: Dashboard = { itemCount: 1675, inventoryValue: INVENTORY, storageValue: STORAGE, + charmsValue: 184.3, unitsLoaded: 4, unitsTotal: 4, },