import { gql, useQuery } from "@apollo/client"; import { Box, Flex, Wrap, WrapItem } from "@chakra-ui/layout"; import { Link } from "react-router-dom"; import HangerSpinner from "./components/HangerSpinner"; import { getValidPoses, useAllValidPetPoses, } from "./components/SpeciesColorPicker"; import { ErrorMessage, Heading1 } from "./util"; import useSupport from "./WardrobePage/support/useSupport"; function SupportPetAppearancesPage() { const { isSupportUser } = useSupport(); if (!isSupportUser) { return "Sorry, this page is only for Support users!"; } return ( <> Support: Pet appearances ); } function UnlabeledPetAppearancesList() { const { loading, error, speciesColorPairs } = useUnlabeledPetAppearances(); return ( These pet appearances have some UNKNOWN poses that need labeled! Please take a look! {loading && ( )} {error && {error.message}} {speciesColorPairs.length > 0 && ( {speciesColorPairs.map(({ species, color }) => ( ))} )} ); } function SpeciesColorEditorLink({ species, color }) { return ( {color.name} {species.name} ); } function useUnlabeledPetAppearances() { const { loading: loadingValids, error: errorValids, valids, } = useAllValidPetPoses({ headers: { "Cache-Control": "no-cache" } }); const { loading: loadingGQL, error: errorGQL, data } = useQuery(gql` query SupportUnlabeledPetAppearances { allColors { id name } allSpecies { id name } } `); const loading = loadingValids || loadingGQL; const error = errorValids || errorGQL; const speciesColorPairs = valids && data?.allColors && data?.allSpecies ? data?.allSpecies .map((species) => data.allColors.map((color) => ({ species, color }))) .flat() .filter(({ species, color }) => { const poses = getValidPoses(valids, species.id, color.id); const hasAllStandardPoses = poses.has("HAPPY_MASC") && poses.has("HAPPY_FEM") && poses.has("SAD_MASC") && poses.has("SAD_FEM") && poses.has("SICK_MASC") && poses.has("SICK_FEM"); const hasAtLeastOneUnknownPose = poses.has("UNKNOWN"); return !hasAllStandardPoses && hasAtLeastOneUnknownPose; }) .sort((a, b) => `${a.species.name} ${a.color.name}`.localeCompare( `${b.species.name} ${b.color.name}` ) ) : []; return { loading, error, speciesColorPairs, }; } export default SupportPetAppearancesPage;