2020-09-06 23:32:04 -07:00
|
|
|
import React from "react";
|
2020-09-15 04:25:48 -07:00
|
|
|
import { Badge, Box, Tooltip } from "@chakra-ui/core";
|
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-11 23:53:57 -07:00
|
|
|
import { Heading1, Heading2, usePageTitle } from "./util";
|
2020-09-11 21:45:38 -07:00
|
|
|
import ItemCard, {
|
|
|
|
ItemBadgeList,
|
2020-09-11 21:53:57 -07:00
|
|
|
ItemCardList,
|
2020-09-15 04:31:27 -07:00
|
|
|
NcBadge,
|
2020-09-11 21:45:38 -07:00
|
|
|
YouOwnThisBadge,
|
|
|
|
} from "./components/ItemCard";
|
2020-09-06 23:32:04 -07:00
|
|
|
|
|
|
|
function ModelingPage() {
|
2020-09-11 23:53:57 -07:00
|
|
|
usePageTitle("Modeling Hub");
|
|
|
|
|
2020-09-06 23:32:04 -07:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Heading1 marginBottom="2">Modeling Hub</Heading1>
|
2020-09-15 03:18:21 -07:00
|
|
|
<ItemModelsSection />
|
2020-09-06 23:32:04 -07:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-15 03:18:21 -07:00
|
|
|
function ItemModelsSection() {
|
2020-09-06 23:32:04 -07:00
|
|
|
const { loading, error, data } = useQuery(gql`
|
|
|
|
query ModelingPage {
|
2020-09-15 03:18:21 -07:00
|
|
|
standardItems: itemsThatNeedModels {
|
|
|
|
...ItemFields
|
2020-09-06 23:32:04 -07:00
|
|
|
speciesThatNeedModels {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 23:58:18 -07:00
|
|
|
|
2020-09-15 03:18:21 -07:00
|
|
|
babyItems: itemsThatNeedModels(colorId: "6") {
|
|
|
|
...ItemFields
|
|
|
|
speciesThatNeedModels(colorId: "6") {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maraquanItems: itemsThatNeedModels(colorId: "44") {
|
|
|
|
...ItemFields
|
|
|
|
speciesThatNeedModels(colorId: "44") {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutantItems: itemsThatNeedModels(colorId: "46") {
|
|
|
|
...ItemFields
|
|
|
|
speciesThatNeedModels(colorId: "46") {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:58:18 -07:00
|
|
|
currentUser {
|
|
|
|
itemsTheyOwn {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 23:32:04 -07:00
|
|
|
}
|
2020-09-15 03:18:21 -07:00
|
|
|
|
|
|
|
fragment ItemFields on Item {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
thumbnailUrl
|
2020-09-15 04:31:27 -07:00
|
|
|
isNc
|
2020-09-15 04:25:48 -07:00
|
|
|
createdAt
|
2020-09-15 03:18:21 -07:00
|
|
|
}
|
2020-09-06 23:32:04 -07:00
|
|
|
`);
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return (
|
2020-09-15 03:18:21 -07:00
|
|
|
<>
|
|
|
|
<Heading2 marginBottom="2">Items we need modeled</Heading2>
|
|
|
|
<Box
|
|
|
|
display="flex"
|
|
|
|
flexDirection="column"
|
|
|
|
alignItems="center"
|
|
|
|
marginTop="8"
|
|
|
|
>
|
|
|
|
<HangerSpinner />
|
|
|
|
<Box fontSize="xs" marginTop="1">
|
|
|
|
<Delay ms={2500}>Checking all the items…</Delay>
|
|
|
|
</Box>
|
2020-09-07 00:34:01 -07:00
|
|
|
</Box>
|
2020-09-15 03:18:21 -07:00
|
|
|
</>
|
2020-09-06 23:32:04 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return <Box color="red.400">{error.message}</Box>;
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:58:18 -07:00
|
|
|
const ownedItemIds = new Set(
|
|
|
|
data.currentUser?.itemsTheyOwn?.map((item) => item.id)
|
|
|
|
);
|
|
|
|
|
2020-09-15 03:18:21 -07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Heading2 marginBottom="2">Items we need modeled</Heading2>
|
|
|
|
<ItemModelsColorSection
|
|
|
|
items={data.standardItems}
|
|
|
|
ownedItemIds={ownedItemIds}
|
|
|
|
/>
|
|
|
|
<Heading2 marginTop="6" marginBottom="2">
|
|
|
|
Items we need modeled on Baby pets
|
|
|
|
</Heading2>
|
|
|
|
<ItemModelsColorSection
|
|
|
|
items={data.babyItems}
|
|
|
|
ownedItemIds={ownedItemIds}
|
|
|
|
/>
|
|
|
|
<Heading2 marginTop="6" marginBottom="2">
|
|
|
|
Items we need modeled on Maraquan pets
|
|
|
|
</Heading2>
|
|
|
|
<ItemModelsColorSection
|
|
|
|
items={data.maraquanItems}
|
|
|
|
ownedItemIds={ownedItemIds}
|
|
|
|
/>
|
|
|
|
<Heading2 marginTop="6">Items we need modeled on Mutant pets</Heading2>
|
|
|
|
<ItemModelsColorSection
|
|
|
|
items={data.mutantItems}
|
|
|
|
ownedItemIds={ownedItemIds}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ItemModelsColorSection({ items, ownedItemIds }) {
|
|
|
|
items = items
|
|
|
|
// enough MMEs are broken that I just don't want to deal right now!
|
|
|
|
// TODO: solve this with our new database omission feature instead?
|
|
|
|
.filter((item) => !item.name.includes("MME"))
|
2020-09-15 04:25:48 -07:00
|
|
|
.sort((a, b) => {
|
|
|
|
// This is a cute sort hack. We sort first by, bringing "New!" to the
|
|
|
|
// top, and then sorting by name _within_ those two groups.
|
|
|
|
const aName = `${itemIsNew(a) ? "000" : "999"} ${a.name}`;
|
|
|
|
const bName = `${itemIsNew(b) ? "000" : "999"} ${b.name}`;
|
|
|
|
return aName.localeCompare(bName);
|
|
|
|
});
|
2020-09-15 03:18:21 -07:00
|
|
|
|
2020-09-06 23:32:04 -07:00
|
|
|
return (
|
2020-09-11 21:53:57 -07:00
|
|
|
<ItemCardList>
|
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-11 21:53:57 -07:00
|
|
|
</ItemCardList>
|
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
|
|
|
|
2020-09-11 21:53:57 -07:00
|
|
|
return <ItemCard item={item} badges={badges} {...props} />;
|
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-15 04:25:48 -07:00
|
|
|
{itemIsNew(item) && <NewItemBadge createdAt={item.createdAt} />}
|
2020-09-15 04:31:27 -07:00
|
|
|
{item.isNc && <NcBadge />}
|
|
|
|
{currentUserOwnsItem && <YouOwnThisBadge />}
|
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-15 04:25:48 -07:00
|
|
|
const fullDateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
|
|
dateStyle: "long",
|
|
|
|
});
|
|
|
|
function NewItemBadge({ createdAt }) {
|
|
|
|
const date = new Date(createdAt);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
label={`Added on ${fullDateFormatter.format(date)}`}
|
|
|
|
placement="top"
|
|
|
|
openDelay={400}
|
|
|
|
>
|
|
|
|
<Badge colorScheme="yellow">New!</Badge>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemIsNew(item) {
|
|
|
|
const date = new Date(item.createdAt);
|
|
|
|
|
|
|
|
const oneMonthAgo = new Date();
|
|
|
|
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
|
|
|
|
|
|
|
|
return date > oneMonthAgo;
|
|
|
|
}
|
|
|
|
|
2020-09-06 23:32:04 -07:00
|
|
|
export default ModelingPage;
|