2020-11-23 11:25:23 -08:00
|
|
|
import React from "react";
|
2021-01-03 19:11:46 -08:00
|
|
|
import { ClassNames } from "@emotion/react";
|
2021-03-23 18:52:01 -07:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
Flex,
|
|
|
|
Skeleton,
|
|
|
|
useColorModeValue,
|
|
|
|
useToken,
|
|
|
|
} from "@chakra-ui/react";
|
2020-11-23 11:25:23 -08:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
import { useQuery } from "@apollo/client";
|
2020-11-24 15:05:23 -08:00
|
|
|
import { Link, useHistory, useParams } from "react-router-dom";
|
2020-11-23 11:25:23 -08:00
|
|
|
|
|
|
|
import { Heading2, usePageTitle } from "./util";
|
|
|
|
import ItemPageLayout from "./ItemPageLayout";
|
2020-11-25 01:53:42 -08:00
|
|
|
import useCurrentUser from "./components/useCurrentUser";
|
2021-03-23 18:52:01 -07:00
|
|
|
import { ChevronDownIcon, ChevronUpIcon } from "@chakra-ui/icons";
|
2020-11-23 11:25:23 -08:00
|
|
|
|
|
|
|
export function ItemTradesOfferingPage() {
|
|
|
|
return (
|
|
|
|
<ItemTradesPage
|
|
|
|
title="Trades: Offering"
|
|
|
|
userHeading="Owner"
|
2020-11-25 02:24:15 -08:00
|
|
|
compareColumnLabel="Trade for your…"
|
2020-11-24 14:24:34 -08:00
|
|
|
tradesQuery={gql`
|
|
|
|
query ItemTradesTableOffering($itemId: ID!) {
|
|
|
|
item(id: $itemId) {
|
|
|
|
id
|
|
|
|
trades: tradesOffering {
|
|
|
|
id
|
|
|
|
user {
|
|
|
|
id
|
|
|
|
username
|
2020-11-24 14:43:43 -08:00
|
|
|
lastTradeActivity
|
2020-11-25 01:53:42 -08:00
|
|
|
matchingItems: itemsTheyWantThatCurrentUserOwns {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
2020-11-24 14:24:34 -08:00
|
|
|
}
|
|
|
|
closetList {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}
|
2020-11-23 11:25:23 -08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ItemTradesSeekingPage() {
|
|
|
|
return (
|
|
|
|
<ItemTradesPage
|
|
|
|
title="Trades: Seeking"
|
|
|
|
userHeading="Seeker"
|
2020-11-25 02:24:15 -08:00
|
|
|
compareColumnLabel="Trade for their…"
|
2020-11-24 14:24:34 -08:00
|
|
|
tradesQuery={gql`
|
|
|
|
query ItemTradesTableSeeking($itemId: ID!) {
|
|
|
|
item(id: $itemId) {
|
|
|
|
id
|
|
|
|
trades: tradesSeeking {
|
|
|
|
id
|
|
|
|
user {
|
|
|
|
id
|
|
|
|
username
|
2020-11-24 14:43:43 -08:00
|
|
|
lastTradeActivity
|
2020-11-25 01:53:42 -08:00
|
|
|
matchingItems: itemsTheyOwnThatCurrentUserWants {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
2020-11-24 14:24:34 -08:00
|
|
|
}
|
|
|
|
closetList {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}
|
2020-11-23 11:25:23 -08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:24:34 -08:00
|
|
|
function ItemTradesPage({
|
|
|
|
title,
|
|
|
|
userHeading,
|
2020-11-25 02:24:15 -08:00
|
|
|
compareColumnLabel,
|
2020-11-24 14:24:34 -08:00
|
|
|
tradesQuery,
|
|
|
|
}) {
|
2020-11-23 11:25:23 -08:00
|
|
|
const { itemId } = useParams();
|
|
|
|
|
2020-11-24 14:24:34 -08:00
|
|
|
const { error, data } = useQuery(
|
2020-11-23 11:25:23 -08:00
|
|
|
gql`
|
|
|
|
query ItemTradesPage($itemId: ID!) {
|
|
|
|
item(id: $itemId) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
isNc
|
|
|
|
isPb
|
|
|
|
thumbnailUrl
|
|
|
|
description
|
|
|
|
createdAt
|
2021-04-07 16:48:41 -07:00
|
|
|
wakaValueText
|
2020-11-23 11:25:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{ variables: { itemId }, returnPartialData: true }
|
|
|
|
);
|
|
|
|
|
2020-11-24 14:24:34 -08:00
|
|
|
usePageTitle(`${data?.item?.name} | ${title}`, { skip: !data?.item?.name });
|
2020-11-23 11:25:23 -08:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return <Box color="red.400">{error.message}</Box>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ItemPageLayout item={data?.item}>
|
|
|
|
<Heading2 marginTop="6" marginBottom="4">
|
|
|
|
{title}
|
|
|
|
</Heading2>
|
|
|
|
<ItemTradesTable
|
|
|
|
itemId={itemId}
|
|
|
|
userHeading={userHeading}
|
2020-11-25 02:24:15 -08:00
|
|
|
compareColumnLabel={compareColumnLabel}
|
2020-11-24 14:24:34 -08:00
|
|
|
tradesQuery={tradesQuery}
|
2020-11-23 11:25:23 -08:00
|
|
|
/>
|
|
|
|
</ItemPageLayout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:24:34 -08:00
|
|
|
function ItemTradesTable({
|
|
|
|
itemId,
|
|
|
|
userHeading,
|
2020-11-25 02:24:15 -08:00
|
|
|
compareColumnLabel,
|
2020-11-24 14:24:34 -08:00
|
|
|
tradesQuery,
|
|
|
|
}) {
|
2020-11-25 01:53:42 -08:00
|
|
|
const { isLoggedIn } = useCurrentUser();
|
2020-11-24 14:24:34 -08:00
|
|
|
const { loading, error, data } = useQuery(tradesQuery, {
|
|
|
|
variables: { itemId },
|
2021-01-21 14:57:21 -08:00
|
|
|
context: { sendAuth: true },
|
2020-11-24 14:24:34 -08:00
|
|
|
});
|
|
|
|
|
2021-03-23 18:52:01 -07:00
|
|
|
const [isShowingInactiveTrades, setIsShowingInactiveTrades] = React.useState(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2020-11-25 01:53:42 -08:00
|
|
|
const shouldShowCompareColumn = isLoggedIn;
|
2020-11-24 14:49:20 -08:00
|
|
|
|
2020-11-25 00:33:00 -08:00
|
|
|
// We partially randomize trade sorting, but we want it to stay stable across
|
|
|
|
// re-renders. To do this, we can use `getTradeSortKey`, which will either
|
|
|
|
// build a new sort key for the trade, or return the cached one from the
|
|
|
|
// `tradeSortKeys` map.
|
|
|
|
const tradeSortKeys = React.useMemo(() => new Map(), []);
|
|
|
|
const getTradeSortKey = (trade) => {
|
|
|
|
if (!tradeSortKeys.has(trade.id)) {
|
|
|
|
tradeSortKeys.set(
|
|
|
|
trade.id,
|
2020-11-25 01:53:42 -08:00
|
|
|
getVaguelyRandomizedTradeSortKey(
|
|
|
|
trade.user.lastTradeActivity,
|
|
|
|
trade.user.matchingItems.length
|
|
|
|
)
|
2020-11-25 00:33:00 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return tradeSortKeys.get(trade.id);
|
|
|
|
};
|
|
|
|
|
2021-03-23 18:52:01 -07:00
|
|
|
const allTrades = [...(data?.item?.trades || [])];
|
|
|
|
|
|
|
|
// Only trades from users active within the last 6 months are shown by
|
|
|
|
// default. The user can toggle to the full view, though!
|
|
|
|
const sixMonthsAgo = new Date();
|
|
|
|
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
|
|
|
|
const activeTrades = allTrades.filter(
|
|
|
|
(t) => new Date(t.user.lastTradeActivity) > sixMonthsAgo
|
|
|
|
);
|
|
|
|
|
|
|
|
const trades = isShowingInactiveTrades ? allTrades : activeTrades;
|
2020-11-25 00:33:00 -08:00
|
|
|
trades.sort((a, b) => getTradeSortKey(b).localeCompare(getTradeSortKey(a)));
|
|
|
|
|
2021-03-23 18:52:01 -07:00
|
|
|
const numInactiveTrades = allTrades.length - activeTrades.length;
|
|
|
|
|
2020-11-25 00:33:00 -08:00
|
|
|
if (error) {
|
|
|
|
return <Box color="red.400">{error.message}</Box>;
|
|
|
|
}
|
2020-11-24 14:58:11 -08:00
|
|
|
|
2020-11-25 01:53:42 -08:00
|
|
|
const minorColumnWidth = {
|
|
|
|
base: shouldShowCompareColumn ? "23%" : "30%",
|
|
|
|
md: "20ex",
|
|
|
|
};
|
|
|
|
|
2020-11-23 11:25:23 -08:00
|
|
|
return (
|
2021-01-03 19:11:46 -08:00
|
|
|
<ClassNames>
|
|
|
|
{({ css }) => (
|
2021-03-23 18:52:01 -07:00
|
|
|
<Box>
|
|
|
|
<Box
|
|
|
|
as="table"
|
|
|
|
width="100%"
|
|
|
|
boxShadow="md"
|
|
|
|
className={css`
|
|
|
|
/* Chakra doesn't have props for these! */
|
|
|
|
border-collapse: separate;
|
|
|
|
border-spacing: 0;
|
|
|
|
table-layout: fixed;
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<Box as="thead" fontSize={{ base: "xs", sm: "sm" }}>
|
|
|
|
<Box as="tr">
|
2021-01-03 19:11:46 -08:00
|
|
|
<ItemTradesTableCell as="th" width={minorColumnWidth}>
|
2021-03-23 18:52:01 -07:00
|
|
|
{/* A small wording tweak to fit better on the xsmall screens! */}
|
|
|
|
<Box display={{ base: "none", sm: "block" }}>Last active</Box>
|
|
|
|
<Box display={{ base: "block", sm: "none" }}>Last edit</Box>
|
2021-01-03 19:11:46 -08:00
|
|
|
</ItemTradesTableCell>
|
2021-03-23 18:52:01 -07:00
|
|
|
{shouldShowCompareColumn && (
|
|
|
|
<ItemTradesTableCell as="th" width={minorColumnWidth}>
|
|
|
|
<Box display={{ base: "none", sm: "block" }}>
|
|
|
|
{compareColumnLabel}
|
|
|
|
</Box>
|
|
|
|
<Box display={{ base: "block", sm: "none" }}>Matches</Box>
|
|
|
|
</ItemTradesTableCell>
|
|
|
|
)}
|
|
|
|
<ItemTradesTableCell as="th" width={minorColumnWidth}>
|
|
|
|
{userHeading}
|
2021-01-03 19:11:46 -08:00
|
|
|
</ItemTradesTableCell>
|
2021-03-23 18:52:01 -07:00
|
|
|
<ItemTradesTableCell as="th">List</ItemTradesTableCell>
|
2020-11-25 01:53:42 -08:00
|
|
|
</Box>
|
2021-03-23 18:52:01 -07:00
|
|
|
</Box>
|
|
|
|
<Box as="tbody">
|
|
|
|
{loading && (
|
|
|
|
<>
|
|
|
|
<ItemTradesTableRowSkeleton
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
<ItemTradesTableRowSkeleton
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
<ItemTradesTableRowSkeleton
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
<ItemTradesTableRowSkeleton
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
<ItemTradesTableRowSkeleton
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{!loading &&
|
|
|
|
trades.length > 0 &&
|
|
|
|
trades.map((trade) => (
|
|
|
|
<ItemTradesTableRow
|
|
|
|
key={trade.id}
|
2021-06-15 22:46:43 -07:00
|
|
|
href={`/user/${trade.user.id}/lists#list-${trade.closetList.id}`}
|
2021-03-23 18:52:01 -07:00
|
|
|
username={trade.user.username}
|
|
|
|
listName={trade.closetList.name}
|
|
|
|
lastTradeActivity={trade.user.lastTradeActivity}
|
|
|
|
matchingItems={trade.user.matchingItems}
|
|
|
|
shouldShowCompareColumn={shouldShowCompareColumn}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{!loading && trades.length === 0 && (
|
|
|
|
<Box as="tr">
|
|
|
|
<ItemTradesTableCell
|
|
|
|
colSpan={shouldShowCompareColumn ? 4 : 3}
|
|
|
|
textAlign="center"
|
|
|
|
fontStyle="italic"
|
|
|
|
>
|
|
|
|
No trades yet!
|
|
|
|
</ItemTradesTableCell>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Box>
|
2020-11-24 14:24:34 -08:00
|
|
|
</Box>
|
2021-03-23 18:52:01 -07:00
|
|
|
{numInactiveTrades > 0 && (
|
|
|
|
<Flex justify="center">
|
|
|
|
<Button
|
|
|
|
size="sm"
|
|
|
|
variant="outline"
|
|
|
|
marginTop="4"
|
|
|
|
onClick={() => setIsShowingInactiveTrades((s) => !s)}
|
|
|
|
>
|
|
|
|
{isShowingInactiveTrades ? (
|
|
|
|
<>
|
|
|
|
<ChevronUpIcon marginRight="2" />
|
|
|
|
Hide {numInactiveTrades} older trades
|
|
|
|
<ChevronUpIcon marginLeft="2" />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<ChevronDownIcon marginRight="2" />
|
|
|
|
Show {numInactiveTrades} more older trades
|
|
|
|
<ChevronDownIcon marginLeft="2" />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Button>
|
|
|
|
</Flex>
|
|
|
|
)}
|
2021-01-03 19:11:46 -08:00
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</ClassNames>
|
2020-11-23 11:25:23 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:43:43 -08:00
|
|
|
function ItemTradesTableRow({
|
|
|
|
href,
|
|
|
|
username,
|
|
|
|
listName,
|
|
|
|
lastTradeActivity,
|
2020-11-25 01:53:42 -08:00
|
|
|
matchingItems,
|
2020-11-24 14:49:20 -08:00
|
|
|
shouldShowCompareColumn,
|
2020-11-24 14:43:43 -08:00
|
|
|
}) {
|
2020-11-23 11:25:23 -08:00
|
|
|
const history = useHistory();
|
|
|
|
const onClick = React.useCallback(() => history.push(href), [history, href]);
|
|
|
|
const focusBackground = useColorModeValue("gray.100", "gray.600");
|
|
|
|
|
2020-11-25 01:53:42 -08:00
|
|
|
const sortedMatchingItems = [...matchingItems].sort((a, b) =>
|
|
|
|
a.name.localeCompare(b.name)
|
|
|
|
);
|
|
|
|
|
2020-11-23 11:25:23 -08:00
|
|
|
return (
|
2021-01-03 19:11:46 -08:00
|
|
|
<ClassNames>
|
|
|
|
{({ css }) => (
|
|
|
|
<Box
|
|
|
|
as="tr"
|
|
|
|
cursor="pointer"
|
|
|
|
_hover={{ background: focusBackground }}
|
|
|
|
_focusWithin={{ background: focusBackground }}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
<ItemTradesTableCell fontSize="xs">
|
|
|
|
{formatVagueDate(lastTradeActivity)}
|
|
|
|
</ItemTradesTableCell>
|
|
|
|
{shouldShowCompareColumn && (
|
|
|
|
<ItemTradesTableCell fontSize="xs">
|
|
|
|
{matchingItems.length > 0 ? (
|
|
|
|
<Box as="ul">
|
|
|
|
{sortedMatchingItems.slice(0, 4).map((item) => (
|
|
|
|
<Box key={item.id} as="li">
|
|
|
|
<Box
|
|
|
|
lineHeight="1.5"
|
|
|
|
maxHeight="1.5em"
|
|
|
|
overflow="hidden"
|
|
|
|
textOverflow="ellipsis"
|
|
|
|
whiteSpace="nowrap"
|
|
|
|
>
|
|
|
|
{item.name}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
))}
|
|
|
|
{matchingItems.length > 4 && (
|
|
|
|
<Box as="li">+ {matchingItems.length - 4} more</Box>
|
|
|
|
)}
|
2020-11-23 11:25:23 -08:00
|
|
|
</Box>
|
2021-01-03 19:11:46 -08:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Box display={{ base: "none", sm: "block" }}>No matches</Box>
|
|
|
|
<Box display={{ base: "block", sm: "none" }}>None</Box>
|
|
|
|
</>
|
2020-11-25 01:53:42 -08:00
|
|
|
)}
|
2021-01-03 19:11:46 -08:00
|
|
|
</ItemTradesTableCell>
|
2020-11-25 01:53:42 -08:00
|
|
|
)}
|
2021-01-03 19:11:46 -08:00
|
|
|
<ItemTradesTableCell fontSize="xs">{username}</ItemTradesTableCell>
|
|
|
|
<ItemTradesTableCell fontSize="sm">
|
|
|
|
<Box
|
|
|
|
as={Link}
|
|
|
|
to={href}
|
|
|
|
className={css`
|
|
|
|
&:hover,
|
|
|
|
&:focus,
|
|
|
|
tr:hover &,
|
|
|
|
tr:focus-within & {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
{listName}
|
|
|
|
</Box>
|
|
|
|
</ItemTradesTableCell>
|
2020-11-24 14:58:11 -08:00
|
|
|
</Box>
|
2021-01-03 19:11:46 -08:00
|
|
|
)}
|
|
|
|
</ClassNames>
|
2020-11-23 11:25:23 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-24 14:58:11 -08:00
|
|
|
function ItemTradesTableRowSkeleton({ shouldShowCompareColumn }) {
|
2020-11-24 14:24:34 -08:00
|
|
|
return (
|
|
|
|
<Box as="tr">
|
|
|
|
<ItemTradesTableCell>
|
2020-11-24 14:29:00 -08:00
|
|
|
<Skeleton width="100%">X</Skeleton>
|
2020-11-24 14:24:34 -08:00
|
|
|
</ItemTradesTableCell>
|
|
|
|
<ItemTradesTableCell>
|
2020-11-24 14:29:00 -08:00
|
|
|
<Skeleton width="100%">X</Skeleton>
|
2020-11-24 14:24:34 -08:00
|
|
|
</ItemTradesTableCell>
|
|
|
|
<ItemTradesTableCell>
|
2020-11-24 14:29:00 -08:00
|
|
|
<Skeleton width="100%">X</Skeleton>
|
2020-11-24 14:24:34 -08:00
|
|
|
</ItemTradesTableCell>
|
2020-11-24 14:58:11 -08:00
|
|
|
{shouldShowCompareColumn && (
|
|
|
|
<ItemTradesTableCell>
|
|
|
|
<Skeleton width="100%">X</Skeleton>
|
|
|
|
</ItemTradesTableCell>
|
|
|
|
)}
|
2020-11-24 14:24:34 -08:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:25:23 -08:00
|
|
|
function ItemTradesTableCell({ children, as = "td", ...props }) {
|
|
|
|
const borderColor = useColorModeValue("gray.300", "gray.400");
|
|
|
|
const borderColorCss = useToken("colors", borderColor);
|
|
|
|
const borderRadiusCss = useToken("radii", "md");
|
|
|
|
|
|
|
|
return (
|
2021-01-03 19:11:46 -08:00
|
|
|
<ClassNames>
|
|
|
|
{({ css }) => (
|
|
|
|
<Box
|
|
|
|
as={as}
|
|
|
|
paddingX="4"
|
|
|
|
paddingY="2"
|
|
|
|
textAlign="left"
|
|
|
|
className={css`
|
|
|
|
/* Lol sigh, getting this right is way more involved than I wish it
|
2020-11-23 11:25:23 -08:00
|
|
|
* were. What I really want is border-collapse and a simple 1px border,
|
|
|
|
* but that disables border-radius. So, we homebrew it by giving all
|
|
|
|
* cells bottom and right borders, but only the cells on the edges a
|
|
|
|
* top or left border; and then target the exact 4 corner cells to
|
|
|
|
* round them. Pretty old-school tbh 🙃 */
|
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
border-bottom: 1px solid ${borderColorCss};
|
|
|
|
border-right: 1px solid ${borderColorCss};
|
2020-11-23 11:25:23 -08:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
thead tr:first-of-type & {
|
|
|
|
border-top: 1px solid ${borderColorCss};
|
|
|
|
}
|
2020-11-23 11:25:23 -08:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
&:first-of-type {
|
|
|
|
border-left: 1px solid ${borderColorCss};
|
|
|
|
}
|
2020-11-23 11:25:23 -08:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
thead tr:first-of-type &:first-of-type {
|
|
|
|
border-top-left-radius: ${borderRadiusCss};
|
|
|
|
}
|
|
|
|
thead tr:first-of-type &:last-of-type {
|
|
|
|
border-top-right-radius: ${borderRadiusCss};
|
|
|
|
}
|
|
|
|
tbody tr:last-of-type &:first-of-type {
|
|
|
|
border-bottom-left-radius: ${borderRadiusCss};
|
|
|
|
}
|
|
|
|
tbody tr:last-of-type &:last-of-type {
|
|
|
|
border-bottom-right-radius: ${borderRadiusCss};
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</ClassNames>
|
2020-11-23 11:25:23 -08:00
|
|
|
);
|
|
|
|
}
|
2020-11-25 00:33:00 -08:00
|
|
|
|
|
|
|
function isThisWeek(date) {
|
|
|
|
const startOfThisWeek = new Date();
|
|
|
|
startOfThisWeek.setDate(startOfThisWeek.getDate() - 7);
|
|
|
|
return date > startOfThisWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shortMonthYearFormatter = new Intl.DateTimeFormat("en", {
|
|
|
|
month: "short",
|
|
|
|
year: "numeric",
|
|
|
|
});
|
|
|
|
|
|
|
|
function formatVagueDate(dateString) {
|
|
|
|
const date = new Date(dateString);
|
|
|
|
|
|
|
|
if (isThisWeek(date)) {
|
|
|
|
return "This week";
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortMonthYearFormatter.format(date);
|
|
|
|
}
|
|
|
|
|
2020-11-25 01:53:42 -08:00
|
|
|
function getVaguelyRandomizedTradeSortKey(dateString, numMatchingItems) {
|
2020-11-25 00:33:00 -08:00
|
|
|
const date = new Date(dateString);
|
2020-11-25 01:53:42 -08:00
|
|
|
const hasMatchingItems = numMatchingItems >= 1;
|
2020-11-25 00:33:00 -08:00
|
|
|
|
|
|
|
// "This week" sorts after all other dates, but with a random factor! I don't
|
|
|
|
// want people worrying about gaming themselves up to the very top, just be
|
|
|
|
// active and trust the system 😅 (I figure that, if you care enough to "game"
|
|
|
|
// the system by faking activity every week, you probably also care enough to
|
|
|
|
// be... making real trades every week lmao)
|
2020-11-25 01:53:42 -08:00
|
|
|
//
|
|
|
|
// We also prioritize having matches, but we don't bother to sort _how many_
|
|
|
|
// matches, to decrease the power of gaming with large honeypot lists, and
|
|
|
|
// because it's hard to judge how good matches are anyway.
|
2020-11-25 00:33:00 -08:00
|
|
|
if (isThisWeek(date)) {
|
2020-11-25 01:53:42 -08:00
|
|
|
const matchingItemsKey = hasMatchingItems
|
|
|
|
? "ZZmatchingZZ"
|
|
|
|
: "AAnotmatchingAA";
|
|
|
|
return `ZZZthisweekZZZ-${matchingItemsKey}-${Math.random()}`;
|
2020-11-25 00:33:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return dateString;
|
|
|
|
}
|