add query to outfit preview, but don't use it yet
This commit is contained in:
parent
881be0c910
commit
f5cb1d263c
3 changed files with 97 additions and 24 deletions
72
src/OutfitPreview.js
Normal file
72
src/OutfitPreview.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
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!) {
|
||||
items(ids: $itemIds) {
|
||||
id
|
||||
appearanceOn(speciesId: $speciesId, colorId: $colorId) {
|
||||
layers {
|
||||
id
|
||||
imageUrl(size: SIZE_600)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ variables: { itemIds, speciesId, colorId } }
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<FullScreenCenter>
|
||||
<Delay>
|
||||
<Spinner color="green.400" size="lg" />
|
||||
</Delay>
|
||||
</FullScreenCenter>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<FullScreenCenter>
|
||||
<Text color="gray.50" d="flex" alignItems="center">
|
||||
<Icon name="warning" />
|
||||
<Box width={2} />
|
||||
Could not load preview. Try again?
|
||||
</Text>
|
||||
</FullScreenCenter>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FullScreenCenter>
|
||||
<Image
|
||||
src="http://pets.neopets.com/cp/wgmdtdwz/1/7.png"
|
||||
maxHeight="100%"
|
||||
maxWidth="100%"
|
||||
/>
|
||||
</FullScreenCenter>
|
||||
);
|
||||
}
|
||||
|
||||
function FullScreenCenter({ children }) {
|
||||
return (
|
||||
<Flex
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
height="100%"
|
||||
width="100%"
|
||||
>
|
||||
{children}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
export default OutfitPreview;
|
|
@ -4,12 +4,10 @@ import {
|
|||
Editable,
|
||||
EditablePreview,
|
||||
EditableInput,
|
||||
Flex,
|
||||
Grid,
|
||||
Heading,
|
||||
Icon,
|
||||
IconButton,
|
||||
Image,
|
||||
Input,
|
||||
InputGroup,
|
||||
InputLeftElement,
|
||||
|
@ -25,6 +23,8 @@ import { ITEMS } from "./data";
|
|||
import ItemList, { ItemListSkeleton } from "./ItemList";
|
||||
import useItemData from "./useItemData";
|
||||
import useOutfitState from "./useOutfitState.js";
|
||||
import OutfitPreview from "./OutfitPreview";
|
||||
import { Delay } from "./util";
|
||||
|
||||
function WardrobePage() {
|
||||
const { loading, error, data, wearItem } = useOutfitState();
|
||||
|
@ -92,8 +92,8 @@ function WardrobePage() {
|
|||
left="0"
|
||||
right="0"
|
||||
>
|
||||
<Box gridArea="outfit">
|
||||
<OutfitPreview />
|
||||
<Box gridArea="outfit" backgroundColor="gray.900">
|
||||
<OutfitPreview itemIds={data.wornItemIds} speciesId="54" colorId="75" />
|
||||
</Box>
|
||||
<Box gridArea="search" boxShadow="sm">
|
||||
<Box px="5" py="3">
|
||||
|
@ -121,24 +121,6 @@ function WardrobePage() {
|
|||
);
|
||||
}
|
||||
|
||||
function OutfitPreview() {
|
||||
return (
|
||||
<Flex
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
height="100%"
|
||||
width="100%"
|
||||
backgroundColor="gray.900"
|
||||
>
|
||||
<Image
|
||||
src="http://pets.neopets.com/cp/wgmdtdwz/1/7.png"
|
||||
maxHeight="100%"
|
||||
maxWidth="100%"
|
||||
/>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
function SearchToolbar({ query, onChange }) {
|
||||
return (
|
||||
<InputGroup>
|
||||
|
@ -243,8 +225,10 @@ function ItemsPanel({ zonesAndItems, loading, onWearItem }) {
|
|||
{loading &&
|
||||
[1, 2, 3].map((i) => (
|
||||
<Box key={i}>
|
||||
<Delay>
|
||||
<Skeleton height="2.3rem" width="12rem" mb="3" />
|
||||
<ItemListSkeleton />
|
||||
</Delay>
|
||||
</Box>
|
||||
))}
|
||||
{!loading &&
|
||||
|
|
17
src/util.js
Normal file
17
src/util.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import React from "react";
|
||||
import { Box } from "@chakra-ui/core";
|
||||
|
||||
export function Delay({ children, ms = 500 }) {
|
||||
const [isVisible, setIsVisible] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
const id = setTimeout(() => setIsVisible(true), ms);
|
||||
return () => clearTimeout(id);
|
||||
}, [ms, setIsVisible]);
|
||||
|
||||
return (
|
||||
<Box opacity={isVisible ? 1 : 0} transition="opacity 0.5s">
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue