2020-09-06 23:32:04 -07:00
|
|
|
import React from "react";
|
2020-09-11 20:41:39 -07:00
|
|
|
import { Badge, Box, SimpleGrid } from "@chakra-ui/core";
|
2020-09-06 23:58:18 -07:00
|
|
|
import { StarIcon } from "@chakra-ui/icons";
|
2020-09-06 23:32:04 -07:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
import { useQuery } from "@apollo/client";
|
|
|
|
|
2020-09-07 00:34:01 -07:00
|
|
|
import { Delay } from "./util";
|
2020-09-06 23:32:04 -07:00
|
|
|
import HangerSpinner from "./components/HangerSpinner";
|
2020-09-06 23:49:04 -07:00
|
|
|
import { Heading1, Heading2 } from "./util";
|
2020-09-11 20:41:39 -07:00
|
|
|
import ItemCard from "./components/ItemCard";
|
|
|
|
import { ItemBadgeList } from "./components/ItemCard";
|
2020-09-06 23:32:04 -07:00
|
|
|
|
|
|
|
function ModelingPage() {
|
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Heading1 marginBottom="2">Modeling Hub</Heading1>
|
2020-09-06 23:49:04 -07:00
|
|
|
<Heading2 marginBottom="2">Item models we need</Heading2>
|
2020-09-06 23:32:04 -07:00
|
|
|
<ItemModelsList />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ItemModelsList() {
|
|
|
|
const { loading, error, data } = useQuery(gql`
|
|
|
|
query ModelingPage {
|
|
|
|
itemsThatNeedModels {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
thumbnailUrl
|
|
|
|
speciesThatNeedModels {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 23:58:18 -07:00
|
|
|
|
|
|
|
currentUser {
|
|
|
|
itemsTheyOwn {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 23:32:04 -07:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return (
|
2020-09-07 00:34:01 -07:00
|
|
|
<Box
|
|
|
|
display="flex"
|
|
|
|
flexDirection="column"
|
|
|
|
alignItems="center"
|
|
|
|
marginTop="16"
|
|
|
|
>
|
2020-09-06 23:32:04 -07:00
|
|
|
<HangerSpinner />
|
2020-09-07 00:34:01 -07:00
|
|
|
<Box fontSize="xs" marginTop="1">
|
|
|
|
<Delay ms={2500}>Checking all the items…</Delay>
|
|
|
|
</Box>
|
2020-09-06 23:32:04 -07:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return <Box color="red.400">{error.message}</Box>;
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:49:04 -07:00
|
|
|
const items = data.itemsThatNeedModels
|
|
|
|
// enough MMEs are broken that I just don't want to deal right now!
|
|
|
|
.filter((item) => !item.name.includes("MME"))
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
2020-09-06 23:32:04 -07:00
|
|
|
|
2020-09-06 23:58:18 -07:00
|
|
|
const ownedItemIds = new Set(
|
|
|
|
data.currentUser?.itemsTheyOwn?.map((item) => item.id)
|
|
|
|
);
|
|
|
|
|
2020-09-06 23:32:04 -07:00
|
|
|
return (
|
2020-09-06 23:49:04 -07:00
|
|
|
<SimpleGrid columns={{ sm: 1, lg: 2 }} spacing="6">
|
2020-09-06 23:32:04 -07:00
|
|
|
{items.map((item) => (
|
2020-09-06 23:58:18 -07:00
|
|
|
<ItemModelCard
|
|
|
|
key={item.id}
|
|
|
|
item={item}
|
|
|
|
currentUserOwnsItem={ownedItemIds.has(item.id)}
|
|
|
|
/>
|
2020-09-06 23:32:04 -07:00
|
|
|
))}
|
2020-09-06 23:49:04 -07:00
|
|
|
</SimpleGrid>
|
2020-09-06 23:32:04 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:58:18 -07:00
|
|
|
function ItemModelCard({ item, currentUserOwnsItem, ...props }) {
|
2020-09-11 20:41:39 -07:00
|
|
|
const badges = (
|
|
|
|
<ItemModelBadges item={item} currentUserOwnsItem={currentUserOwnsItem} />
|
2020-09-06 23:32:04 -07:00
|
|
|
);
|
2020-09-11 20:41:39 -07:00
|
|
|
|
|
|
|
return <ItemCard item={item} badges={badges} />;
|
2020-09-06 23:32:04 -07:00
|
|
|
}
|
|
|
|
|
2020-09-06 23:58:18 -07:00
|
|
|
function ItemModelBadges({ item, currentUserOwnsItem }) {
|
2020-09-06 23:49:04 -07:00
|
|
|
return (
|
2020-09-11 20:41:39 -07:00
|
|
|
<ItemBadgeList>
|
2020-09-06 23:58:18 -07:00
|
|
|
{currentUserOwnsItem && (
|
|
|
|
<Badge colorScheme="yellow" display="flex" alignItems="center">
|
|
|
|
<StarIcon aria-label="Star" marginRight="1" />
|
|
|
|
You own this!
|
|
|
|
</Badge>
|
|
|
|
)}
|
2020-09-06 23:49:04 -07:00
|
|
|
{item.speciesThatNeedModels.map((species) => (
|
|
|
|
<Badge>{species.name}</Badge>
|
|
|
|
))}
|
2020-09-11 20:41:39 -07:00
|
|
|
</ItemBadgeList>
|
2020-09-06 23:49:04 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:32:04 -07:00
|
|
|
export default ModelingPage;
|