From fd3752e38b2b5a836a78779a411fad99ff2e7d7c Mon Sep 17 00:00:00 2001 From: Aodhan Date: Thu, 10 Jul 2025 18:25:23 +0100 Subject: [PATCH] Fixed recipe bug n inventory page. --- backend/app/recipes_router.py | 5 ++--- frontend/src/components/ItemDetailPanel.tsx | 6 ++++-- frontend/src/utils/nameSubstitutions.ts | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/app/recipes_router.py b/backend/app/recipes_router.py index 054be51..73fec56 100644 --- a/backend/app/recipes_router.py +++ b/backend/app/recipes_router.py @@ -13,9 +13,8 @@ from pydantic import BaseModel from .database import get_session -# Map craft names -> table names in Postgres -ALLOWED_CRAFTS = { - "desynthesis": "recipes_desynthesis", +# Map craft names to their corresponding recipe tables in Postgres. +ALLOWED_CRAFTS: dict[str, str] = { "woodworking": "recipes_woodworking", "smithing": "recipes_smithing", "alchemy": "recipes_alchemy", diff --git a/frontend/src/components/ItemDetailPanel.tsx b/frontend/src/components/ItemDetailPanel.tsx index fefaae6..2d31bfe 100644 --- a/frontend/src/components/ItemDetailPanel.tsx +++ b/frontend/src/components/ItemDetailPanel.tsx @@ -10,6 +10,7 @@ import { useQuery } from "@tanstack/react-query"; import { api } from "../api"; import CircularProgress from "@mui/material/CircularProgress"; import { craftColors } from "../constants/colors"; +import { reverseSubstitutions } from "../utils/nameSubstitutions"; export interface ItemSummary { id: number; @@ -47,7 +48,8 @@ export default function ItemDetailPanel({ open, item, onClose }: Props) { queryFn: async () => { if (!item) return null; try { - const res = await api.get(`/recipes/usage/${encodeURIComponent(item.name)}`); + const searchName = reverseSubstitutions(item.name); + const res = await api.get(`/recipes/usage/${encodeURIComponent(searchName)}`); return res.data as Usage; } catch { return null; @@ -79,7 +81,7 @@ export default function ItemDetailPanel({ open, item, onClose }: Props) { diff --git a/frontend/src/utils/nameSubstitutions.ts b/frontend/src/utils/nameSubstitutions.ts index 6598b84..837f186 100644 --- a/frontend/src/utils/nameSubstitutions.ts +++ b/frontend/src/utils/nameSubstitutions.ts @@ -18,12 +18,15 @@ export const SUBSTITUTE_MAP: Array<[string, string]> = [ ["Fishing Rod","Fish. Rod"], ["Black Bolt Heads","Blk. Bolt HeadsBlk. Bolt Heads"], ["Ethereal Oak Lumber","Ether. Oak Lbr."], + ["Windurstian Tea Leaves","Win. Tea Leaves"], + ["Forgotten Thought", "Frgtn. Thought"] // add more substitutions here ]; export function applySubstitutions(name: string): string { + let result = name; for (const [from, to] of SUBSTITUTE_MAP) { if (result.includes(from)) { @@ -32,3 +35,14 @@ export function applySubstitutions(name: string): string { } return result; } + +// Reverse substitution: replace abbreviated form with full name. +export function reverseSubstitutions(name: string): string { + let result = name; + for (const [from, to] of SUBSTITUTE_MAP) { + if (result.includes(to)) { + result = result.replace(to, from); + } + } + return result; +}