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, useLocation } from "react-router-dom"; import { Heading1, MajorErrorMessage, useCommonStyles } from "./util"; import HangerSpinner from "./components/HangerSpinner"; import OutfitThumbnail from "./components/OutfitThumbnail"; import useRequireLogin from "./components/useRequireLogin"; import PaginationToolbar from "./components/PaginationToolbar"; function UserOutfitsPage() { return ( Your outfits ); } function UserOutfitsPageContent() { const { isLoading: userLoading } = useRequireLogin(); const { search } = useLocation(); const offset = parseInt(new URLSearchParams(search).get("offset")) || 0; const { loading: queryLoading, error, data } = useQuery( gql` query UserOutfitsPageContent($offset: Int!) { currentUser { id numTotalOutfits outfits(limit: 20, offset: $offset) { id name updatedAt # For alt text petAppearance { species { id name } color { id name } } wornItems { id name } } } } `, { variables: { offset }, context: { sendAuth: true }, skip: userLoading, // This will give us the cached numTotalOutfits while we wait for the // next page! returnPartialData: true, } ); const isLoading = userLoading || queryLoading; if (error) { return ; } const outfits = data?.currentUser?.outfits || []; return ( {isLoading ? (
) : outfits.length === 0 ? ( You don't have any outfits yet. Maybe you can create some! ) : ( {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;