From e788040315060362a3c7f1a822ad88579fb859bc Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 2 Feb 2021 16:29:20 -0800 Subject: [PATCH] Guess when item is species-specific, for UI hints --- src/app/ItemPage.js | 58 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/app/ItemPage.js b/src/app/ItemPage.js index eb9d146..70a0c0f 100644 --- a/src/app/ItemPage.js +++ b/src/app/ItemPage.js @@ -518,6 +518,7 @@ function ItemPageOutfitPreview({ itemId }) { query ItemPageOutfitPreview($itemId: ID!) { item(id: $itemId) { id + name compatibleBodies { id representsAllBodies @@ -531,6 +532,7 @@ function ItemPageOutfitPreview({ itemId }) { id species { id + name } color { id @@ -565,6 +567,23 @@ function ItemPageOutfitPreview({ itemId }) { const compatibleBodies = data?.item?.compatibleBodies || []; + // If there's only one compatible body, and the canonical species's name + // 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 isProbablySpeciesSpecific = + compatibleBodies.length === 1 && + !compatibleBodies[0].representsAllBodies && + (data?.item?.name || "").includes( + data?.item?.canonicalAppearance?.body?.canonicalAppearance?.species?.name + ); + const couldProbablyModelMoreData = !isProbablySpeciesSpecific; + console.log( + compatibleBodies, + data?.item?.name, + data?.item?.canonicalAppearance?.body?.canonicalAppearance?.species?.name + ); + // To check whether the item is compatible with this pet, query for the // appearance, but only against the cache. That way, we don't send a // redundant network request just for this (the OutfitPreview component will @@ -681,7 +700,14 @@ function ItemPageOutfitPreview({ itemId }) { /> {isIncompatible && ( - + setPetState({ speciesId, @@ -761,6 +788,7 @@ function PlayPauseButton({ isPaused, onClick }) { function SpeciesFacesPicker({ selectedSpeciesId, compatibleBodies, + couldProbablyModelMoreData, onChange, isLoading, }) { @@ -807,6 +835,7 @@ function SpeciesFacesPicker({ compatibleBodyIds.includes(speciesFace.bodyId) } isSelected={speciesFace.speciesId === selectedSpeciesId} + couldProbablyModelMoreData={couldProbablyModelMoreData} onChange={onChange} isLoading={isLoading} /> @@ -833,6 +862,7 @@ function SpeciesFaceOption({ neopetsImageHash, isCompatible, isSelected, + couldProbablyModelMoreData, onChange, isLoading, }) { @@ -864,7 +894,9 @@ function SpeciesFaceOption({ {speciesName} {!isLoading && !isCompatible && (
- (Not compatible yet) + {couldProbablyModelMoreData + ? "(Not modeled yet)" + : "(Not compatible)"}
)} @@ -898,7 +930,10 @@ function SpeciesFaceOption({ name="species-faces-picker" value={speciesId} checked={isSelected} - disabled={isLoading || !isCompatible} + // It's possible to get this selected via the SpeciesColorPicker, + // even if this would normally be disabled. If so, make this + // option enabled, so keyboard users can focus and change it. + disabled={!isSelected && (isLoading || !isCompatible)} onChange={() => onChange({ speciesId, colorId })} onFocus={() => setInputIsFocused(true)} onBlur={() => setInputIsFocused(false)} @@ -933,11 +968,22 @@ function SpeciesFaceOption({ alt={speciesName} width={50} height={50} - filter={isCompatible ? "saturate(90%)" : "saturate(0%)"} - opacity={isCompatible ? "0.9" : "0.6"} + data-is-compatible={isCompatible} transition="all 0.2s" className={css` - input:checked + * & { + filter: saturate(90%); + opacity: 0.9; + + &[data-is-compatible="false"] { + filter: saturate(0%); + opacity: 0.6; + } + + input:checked + * &[data-is-compatible="false"] { + opacity: 0.85; + } + + input:checked + * &[data-is-compatible="true"] { opacity: 1; filter: saturate(110%); }