import React from "react"; import { Box, Center, Flex, Wrap, WrapItem } from "@chakra-ui/react"; import { ClassNames } from "@emotion/react"; import gql from "graphql-tag"; import { useQuery } from "@apollo/client"; import { Link } from "react-router-dom"; import { ErrorMessage, Heading1, useCommonStyles } from "./util"; import HangerSpinner from "./components/HangerSpinner"; import OutfitThumbnail, { outfitThumbnailFragment, getOutfitThumbnailRenderSize, } from "./components/OutfitThumbnail"; import useRequireLogin from "./components/useRequireLogin"; import WIPCallout from "./components/WIPCallout"; function UserOutfitsPage() { return ( Your outfits ); } function UserOutfitsPageContent() { const { isLoading: userLoading } = useRequireLogin(); const { loading: queryLoading, error, data } = useQuery( gql` query UserOutfitsPageContent($size: LayerImageSize) { currentUser { id outfits { id name ...OutfitThumbnailFragment # For alt text petAppearance { species { id name } color { id name } } wornItems { id name } } } } ${outfitThumbnailFragment} `, { variables: { // NOTE: This parameter is used inside `OutfitThumbnailFragment`! size: "SIZE_" + getOutfitThumbnailRenderSize(), }, context: { sendAuth: true }, skip: userLoading, } ); if (userLoading || queryLoading) { return (
); } if (error) { return Error loading outfits: {error.message}; } const outfits = data.currentUser.outfits; if (outfits.length === 0) { return ( You don't have any outfits yet. Maybe you can create some! ); } return ( {outfits.map((outfit) => ( ))} ); } function OutfitCard({ outfit }) { const image = ( {({ css }) => ( )} ); return ( ); } function OutfitCardLayout({ image, caption }) { const { brightBackground } = useCommonStyles(); return ( {image} {caption} ); } function buildOutfitAltText(outfit) { const { petAppearance, wornItems } = outfit; const { species, color } = petAppearance; let altText = ""; const petDescription = `${color.name} ${species.name}`; altText += petDescription; if (wornItems.length > 0) { const itemNames = wornItems .map((item) => item.name) .sort() .join(", "); altText += ` wearing ${itemNames}`; } return altText; } export default UserOutfitsPage;