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 { Link, 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};
}
// HACK: I'm pretty much hiding this for now, because it's not ready. But
/// it's visible at #show-compare-column!
const shouldShowCompareColumn = window.location.href.includes(
"show-compare-column"
);
const minorColumnWidth = {
base: shouldShowCompareColumn ? "23%" : "30%",
md: "18ex",
};
const trades = [...(data?.item?.trades || [])].sort(
(a, b) =>
new Date(b.user.lastTradeActivity) - new Date(a.user.lastTradeActivity)
);
return (
{/* A small wording tweak to fit better on the xsmall screens! */}
Last active
Last edit
{userHeading}
{shouldShowCompareColumn && (
Compare
)}
List
{loading && (
<>
>
)}
{!loading &&
trades.length > 0 &&
trades.map((trade) => (
))}
{!loading && trades.length === 0 && (
No trades yet!
)}
);
}
function ItemTradesTableRow({
compareListHeading,
href,
username,
listName,
lastTradeActivity,
shouldShowCompareColumn,
}) {
const history = useHistory();
const onClick = React.useCallback(() => history.push(href), [history, href]);
const focusBackground = useColorModeValue("gray.100", "gray.600");
return (
{new Intl.DateTimeFormat("en", {
month: "short",
year: "numeric",
}).format(new Date(lastTradeActivity))}
{username}
{shouldShowCompareColumn && (
{compareListHeading}:
Adorable Freckles
Constellation Dress
(WIP: This is placeholder data!)
}
>
2 match
2 matches
)}
{listName}
);
}
function ItemTradesTableRowSkeleton({ shouldShowCompareColumn }) {
return (
X
X
X
{shouldShowCompareColumn && (
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}
);
}