From b54be0ab5c47f3f05ab4f3c024d333b6e93f24cf Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 11 Nov 2023 08:50:32 -0800 Subject: [PATCH] Load item name from Rails app in item preview page This is just a silly lil single-field migration! --- app/javascript/wardrobe-2020/ItemPageOutfitPreview.js | 11 +++++------ app/javascript/wardrobe-2020/loaders/items.js | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/javascript/wardrobe-2020/ItemPageOutfitPreview.js b/app/javascript/wardrobe-2020/ItemPageOutfitPreview.js index ffe6ea25..9d6e5b47 100644 --- a/app/javascript/wardrobe-2020/ItemPageOutfitPreview.js +++ b/app/javascript/wardrobe-2020/ItemPageOutfitPreview.js @@ -105,6 +105,7 @@ function ItemPageOutfitPreview({ itemId }) { loading: loadingAppearances, error: errorAppearances, } = useItemAppearances(itemId); + const itemName = itemAppearancesData?.name ?? ""; const itemAppearances = itemAppearancesData?.appearances ?? []; const restrictedZones = itemAppearancesData?.restrictedZones ?? []; @@ -132,7 +133,6 @@ function ItemPageOutfitPreview({ itemId }) { ) { item(id: $itemId) { id - name canonicalAppearance( preferredSpeciesId: $preferredSpeciesId preferredColorId: $preferredColorId @@ -189,14 +189,13 @@ function ItemPageOutfitPreview({ itemId }) { // appears in the item name, then this is probably a species-specific item, // and we should adjust the UI to avoid implying that other species could // model it. + const speciesName = + data?.item?.canonicalAppearance?.body?.canonicalAppearance?.species?.name ?? + ""; const isProbablySpeciesSpecific = compatibleBodies.length === 1 && compatibleBodies[0] !== "all" && - (data?.item?.name || "") - .toLowerCase() - .includes( - data?.item?.canonicalAppearance?.body?.canonicalAppearance?.species?.name.toLowerCase(), - ); + itemName.toLowerCase().includes(speciesName.toLowerCase()); const couldProbablyModelMoreData = !isProbablySpeciesSpecific; // TODO: Does this double-trigger the HTTP request with SpeciesColorPicker? diff --git a/app/javascript/wardrobe-2020/loaders/items.js b/app/javascript/wardrobe-2020/loaders/items.js index 1387e39b..4b796bce 100644 --- a/app/javascript/wardrobe-2020/loaders/items.js +++ b/app/javascript/wardrobe-2020/loaders/items.js @@ -22,6 +22,7 @@ async function loadItemAppearancesData(id) { function normalizeItemAppearancesData(data) { return { + name: data.name, appearances: data.appearances.map((appearance) => ({ body: normalizeBody(appearance.body), swfAssets: appearance.swf_assets.map((asset) => ({