use preloaded pet data when loading item page
This commit is contained in:
parent
a6761a2403
commit
5c8fbdc81e
1 changed files with 16 additions and 9 deletions
|
@ -443,14 +443,26 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const [petState, setPetState] = React.useState({
|
const [petState, setPetState] = React.useState({
|
||||||
// We'll fill this in once the canonical appearance data arrives.
|
// We'll fill these in once the canonical appearance data arrives.
|
||||||
speciesId: null,
|
speciesId: null,
|
||||||
colorId: null,
|
colorId: null,
|
||||||
pose: null,
|
pose: null,
|
||||||
|
|
||||||
|
// We use appearance ID, in addition to the above, to give the Apollo cache
|
||||||
|
// a really clear hint that the canonical pet appearance we preloaded is
|
||||||
|
// the exact right one to show! But switching species/color will null this
|
||||||
|
// out again, and that's okay. (We'll do an unnecessary reload if you
|
||||||
|
// switch back to it though... we could maybe do something clever there!)
|
||||||
|
appearanceId: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start by loading the "canonical" pet and item appearance for the outfit
|
// Start by loading the "canonical" pet and item appearance for the outfit
|
||||||
// preview. We'll use this to initialize both the preview and the picker.
|
// preview. We'll use this to initialize both the preview and the picker.
|
||||||
|
//
|
||||||
|
// TODO: If this is a non-standard pet color, like Mutant, we'll do an extra
|
||||||
|
// query after this loads, because our Apollo cache can't detect the
|
||||||
|
// shared item appearance. (For standard colors though, our logic to
|
||||||
|
// cover standard-color switches works for this preloading too.)
|
||||||
const { loading, error } = useQuery(
|
const { loading, error } = useQuery(
|
||||||
gql`
|
gql`
|
||||||
query ItemPageOutfitPreview($itemId: ID!) {
|
query ItemPageOutfitPreview($itemId: ID!) {
|
||||||
|
@ -491,6 +503,7 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
speciesId: canonicalPetAppearance?.species?.id,
|
speciesId: canonicalPetAppearance?.species?.id,
|
||||||
colorId: canonicalPetAppearance?.color?.id,
|
colorId: canonicalPetAppearance?.color?.id,
|
||||||
pose: canonicalPetAppearance?.pose,
|
pose: canonicalPetAppearance?.pose,
|
||||||
|
appearanceId: canonicalPetAppearance?.id,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -523,7 +536,6 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
colorId: petState.colorId,
|
colorId: petState.colorId,
|
||||||
},
|
},
|
||||||
fetchPolicy: "cache-only",
|
fetchPolicy: "cache-only",
|
||||||
onCompleted: (data) => console.log("data", data),
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -539,13 +551,6 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
// non-empty array, then we're compatible!
|
// non-empty array, then we're compatible!
|
||||||
const layers = cachedData?.item?.appearanceOn?.layers;
|
const layers = cachedData?.item?.appearanceOn?.layers;
|
||||||
const isIncompatible = Array.isArray(layers) && layers.length === 0;
|
const isIncompatible = Array.isArray(layers) && layers.length === 0;
|
||||||
console.log(
|
|
||||||
petState.speciesId,
|
|
||||||
petState.colorId,
|
|
||||||
itemId,
|
|
||||||
layers,
|
|
||||||
isIncompatible
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack spacing="3" width="100%">
|
<VStack spacing="3" width="100%">
|
||||||
|
@ -565,6 +570,7 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
speciesId={petState.speciesId}
|
speciesId={petState.speciesId}
|
||||||
colorId={petState.colorId}
|
colorId={petState.colorId}
|
||||||
pose={petState.pose}
|
pose={petState.pose}
|
||||||
|
appearanceId={petState.appearanceId}
|
||||||
wornItemIds={[itemId]}
|
wornItemIds={[itemId]}
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
spinnerVariant="corner"
|
spinnerVariant="corner"
|
||||||
|
@ -588,6 +594,7 @@ function ItemPageOutfitPreview({ itemId }) {
|
||||||
speciesId: species.id,
|
speciesId: species.id,
|
||||||
colorId: color.id,
|
colorId: color.id,
|
||||||
pose: closestPose,
|
pose: closestPose,
|
||||||
|
appearanceId: null,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|
Loading…
Reference in a new issue