preload preview data for closeted items

This commit is contained in:
Matt Dunn-Rankin 2020-04-24 20:28:40 -07:00
parent f49c2552ce
commit 66b0314990
2 changed files with 28 additions and 26 deletions

View file

@ -8,6 +8,23 @@ import { Delay } from "./util";
import "./OutfitPreview.css"; import "./OutfitPreview.css";
export const itemAppearanceFragment = gql`
fragment AppearanceForOutfitPreview on Appearance {
layers {
id
imageUrl(size: SIZE_600)
zone {
id
depth
}
}
restrictedZones {
id
}
}
`;
function OutfitPreview({ outfitState }) { function OutfitPreview({ outfitState }) {
const { wornItemIds, speciesId, colorId } = outfitState; const { wornItemIds, speciesId, colorId } = outfitState;
@ -15,38 +32,17 @@ function OutfitPreview({ outfitState }) {
gql` gql`
query($wornItemIds: [ID!]!, $speciesId: ID!, $colorId: ID!) { query($wornItemIds: [ID!]!, $speciesId: ID!, $colorId: ID!) {
petAppearance(speciesId: $speciesId, colorId: $colorId) { petAppearance(speciesId: $speciesId, colorId: $colorId) {
layers { ...AppearanceForOutfitPreview
id
imageUrl(size: SIZE_600)
zone {
id
depth
}
}
restrictedZones {
id
}
} }
items(ids: $wornItemIds) { items(ids: $wornItemIds) {
id id
appearanceOn(speciesId: $speciesId, colorId: $colorId) { appearanceOn(speciesId: $speciesId, colorId: $colorId) {
layers { ...AppearanceForOutfitPreview
id
imageUrl(size: SIZE_600)
zone {
id
depth
}
}
restrictedZones {
id
}
} }
} }
} }
${itemAppearanceFragment}
`, `,
{ {
variables: { wornItemIds, speciesId, colorId }, variables: { wornItemIds, speciesId, colorId },

View file

@ -1,6 +1,8 @@
import gql from "graphql-tag"; import gql from "graphql-tag";
import { useQuery } from "@apollo/react-hooks"; import { useQuery } from "@apollo/react-hooks";
import { itemAppearanceFragment } from "./OutfitPreview";
function useItemData(itemIds, speciesId, colorId) { function useItemData(itemIds, speciesId, colorId) {
const { loading, error, data } = useQuery( const { loading, error, data } = useQuery(
gql` gql`
@ -10,9 +12,12 @@ function useItemData(itemIds, speciesId, colorId) {
name name
thumbnailUrl thumbnailUrl
# This is used to group items by zone, and to detect conflicts when
# wearing a new item.
appearanceOn(speciesId: $speciesId, colorId: $colorId) { appearanceOn(speciesId: $speciesId, colorId: $colorId) {
# This enables us to quickly show the item when the user clicks it!
...AppearanceForOutfitPreview
# This is used to group items by zone, and to detect conflicts when
# wearing a new item.
layers { layers {
zone { zone {
id id
@ -22,6 +27,7 @@ function useItemData(itemIds, speciesId, colorId) {
} }
} }
} }
${itemAppearanceFragment}
`, `,
{ variables: { itemIds, speciesId, colorId } } { variables: { itemIds, speciesId, colorId } }
); );