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,
|
Editable,
|
||||||
EditablePreview,
|
EditablePreview,
|
||||||
EditableInput,
|
EditableInput,
|
||||||
Flex,
|
|
||||||
Grid,
|
Grid,
|
||||||
Heading,
|
Heading,
|
||||||
Icon,
|
Icon,
|
||||||
IconButton,
|
IconButton,
|
||||||
Image,
|
|
||||||
Input,
|
Input,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
InputLeftElement,
|
InputLeftElement,
|
||||||
|
@ -25,6 +23,8 @@ import { ITEMS } from "./data";
|
||||||
import ItemList, { ItemListSkeleton } from "./ItemList";
|
import ItemList, { ItemListSkeleton } from "./ItemList";
|
||||||
import useItemData from "./useItemData";
|
import useItemData from "./useItemData";
|
||||||
import useOutfitState from "./useOutfitState.js";
|
import useOutfitState from "./useOutfitState.js";
|
||||||
|
import OutfitPreview from "./OutfitPreview";
|
||||||
|
import { Delay } from "./util";
|
||||||
|
|
||||||
function WardrobePage() {
|
function WardrobePage() {
|
||||||
const { loading, error, data, wearItem } = useOutfitState();
|
const { loading, error, data, wearItem } = useOutfitState();
|
||||||
|
@ -92,8 +92,8 @@ function WardrobePage() {
|
||||||
left="0"
|
left="0"
|
||||||
right="0"
|
right="0"
|
||||||
>
|
>
|
||||||
<Box gridArea="outfit">
|
<Box gridArea="outfit" backgroundColor="gray.900">
|
||||||
<OutfitPreview />
|
<OutfitPreview itemIds={data.wornItemIds} speciesId="54" colorId="75" />
|
||||||
</Box>
|
</Box>
|
||||||
<Box gridArea="search" boxShadow="sm">
|
<Box gridArea="search" boxShadow="sm">
|
||||||
<Box px="5" py="3">
|
<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 }) {
|
function SearchToolbar({ query, onChange }) {
|
||||||
return (
|
return (
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
|
@ -243,8 +225,10 @@ function ItemsPanel({ zonesAndItems, loading, onWearItem }) {
|
||||||
{loading &&
|
{loading &&
|
||||||
[1, 2, 3].map((i) => (
|
[1, 2, 3].map((i) => (
|
||||||
<Box key={i}>
|
<Box key={i}>
|
||||||
<Skeleton height="2.3rem" width="12rem" mb="3" />
|
<Delay>
|
||||||
<ItemListSkeleton />
|
<Skeleton height="2.3rem" width="12rem" mb="3" />
|
||||||
|
<ItemListSkeleton />
|
||||||
|
</Delay>
|
||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
{!loading &&
|
{!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