diff --git a/src/OutfitPreview.js b/src/OutfitPreview.js new file mode 100644 index 0000000..a8c44bc --- /dev/null +++ b/src/OutfitPreview.js @@ -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 ( + + + + + + ); + } + + if (error) { + return ( + + + + + Could not load preview. Try again? + + + ); + } + + return ( + + + + ); +} + +function FullScreenCenter({ children }) { + return ( + + {children} + + ); +} + +export default OutfitPreview; diff --git a/src/WardrobePage.js b/src/WardrobePage.js index 876b683..947aceb 100644 --- a/src/WardrobePage.js +++ b/src/WardrobePage.js @@ -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" > - - + + @@ -121,24 +121,6 @@ function WardrobePage() { ); } -function OutfitPreview() { - return ( - - - - ); -} - function SearchToolbar({ query, onChange }) { return ( @@ -243,8 +225,10 @@ function ItemsPanel({ zonesAndItems, loading, onWearItem }) { {loading && [1, 2, 3].map((i) => ( - - + + + + ))} {!loading && diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..7dc8325 --- /dev/null +++ b/src/util.js @@ -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 ( + + {children} + + ); +}