import React from "react";
import gql from "graphql-tag";
import { useQuery } from "@apollo/react-hooks";
import { Flex, Image, Spinner, Text, Icon, Box } from "@chakra-ui/core";
import { Delay } from "./util";
function OutfitPreview({ itemIds, speciesId, colorId }) {
const { loading, error, data } = useQuery(
gql`
query($itemIds: [ID!]!, $speciesId: ID!, $colorId: ID!) {
petAppearance(speciesId: $speciesId, colorId: $colorId) {
layers {
id
imageUrl(size: SIZE_600)
zone {
id
depth
}
}
restrictedZones {
id
}
}
items(ids: $itemIds) {
id
appearanceOn(speciesId: $speciesId, colorId: $colorId) {
layers {
id
imageUrl(size: SIZE_600)
zone {
id
depth
}
}
restrictedZones {
id
}
}
}
}
`,
{ variables: { itemIds, speciesId, colorId } }
);
if (error) {
return (
Could not load preview. Try again?
);
}
return (
{getVisibleLayers(data).map((layer) => (
))}
{loading && (
)}
);
}
function getVisibleLayers(data) {
if (!data) {
return [];
}
const allAppearances = [
data.petAppearance,
...data.items.map((i) => i.appearanceOn),
];
const allLayers = allAppearances.map((a) => a.layers).flat();
const allRestrictedZoneIds = allAppearances
.map((l) => l.restrictedZones)
.flat()
.map((z) => z.id);
const visibleLayers = allLayers.filter(
(l) => !allRestrictedZoneIds.includes(l.zone.id)
);
visibleLayers.sort((a, b) => a.zone.depth - b.zone.depth);
return visibleLayers;
}
function FullScreenCenter({ children }) {
return (
{children}
);
}
export default OutfitPreview;