import React from "react";
import { css } from "emotion";
import {
Box,
Skeleton,
Tooltip,
useColorModeValue,
useToken,
} from "@chakra-ui/core";
import gql from "graphql-tag";
import { useQuery } from "@apollo/client";
import { useHistory, useParams } from "react-router-dom";
import { Heading2, usePageTitle } from "./util";
import ItemPageLayout from "./ItemPageLayout";
export function ItemTradesOfferingPage() {
return (
);
}
export function ItemTradesSeekingPage() {
return (
);
}
function ItemTradesPage({
title,
userHeading,
compareListHeading,
tradesQuery,
}) {
const { itemId } = useParams();
const { error, data } = useQuery(
gql`
query ItemTradesPage($itemId: ID!) {
item(id: $itemId) {
id
name
isNc
isPb
thumbnailUrl
description
createdAt
}
}
`,
{ variables: { itemId }, returnPartialData: true }
);
usePageTitle(`${data?.item?.name} | ${title}`, { skip: !data?.item?.name });
if (error) {
return {error.message};
}
return (
{title}
);
}
function ItemTradesTable({
itemId,
userHeading,
compareListHeading,
tradesQuery,
}) {
const { loading, error, data } = useQuery(tradesQuery, {
variables: { itemId },
});
if (error) {
return {error.message};
}
return (
List
{userHeading}
{/* A small wording tweak to fit better on the xsmall screens! */}
Last active
Active at
Compare
{loading && (
<>
>
)}
{!loading &&
data.item.trades.length > 0 &&
data.item.trades.map((trade) => (
))}
{!loading && data.item.trades.length === 0 && (
No trades yet!
)}
);
}
function ItemTradesTableRow({
compareListHeading,
href,
username,
listName,
lastTradeActivity,
}) {
const history = useHistory();
const onClick = React.useCallback(() => history.push(href), [history, href]);
const focusBackground = useColorModeValue("gray.100", "gray.600");
return (
{listName}
{username}
{new Intl.DateTimeFormat("en", {
month: "short",
year: "numeric",
}).format(new Date(lastTradeActivity))}
{compareListHeading}:
Adorable Freckles
Constellation Dress
(WIP: This is placeholder data!)
}
>
2 match
2 matches
);
}
function ItemTradesTableRowSkeleton() {
return (
X
X
X
X
);
}
function ItemTradesTableCell({ children, as = "td", ...props }) {
const borderColor = useColorModeValue("gray.300", "gray.400");
const borderColorCss = useToken("colors", borderColor);
const borderRadiusCss = useToken("radii", "md");
return (
{children}
);
}