Add NC/NP tags to homepage & search result items

This commit is contained in:
Emi Matchu 2021-04-01 20:08:35 -07:00
parent 02228f533a
commit 6f6fc264af
3 changed files with 86 additions and 20 deletions

View file

@ -362,6 +362,7 @@ function NewItemsSectionContent() {
id id
name name
thumbnailUrl thumbnailUrl
isNc
} }
} }
` `

View file

@ -144,6 +144,7 @@ function ItemSearchPageResults({ query: latestQuery, offset }) {
id id
name name
thumbnailUrl thumbnailUrl
isNc
} }
} }
} }

View file

@ -1,12 +1,17 @@
import React from "react"; import React from "react";
import { Skeleton, useTheme, useToken } from "@chakra-ui/react"; import {
Skeleton,
useColorModeValue,
useTheme,
useToken,
} from "@chakra-ui/react";
import { ClassNames } from "@emotion/react"; import { ClassNames } from "@emotion/react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { safeImageUrl, useCommonStyles } from "../util"; import { safeImageUrl, useCommonStyles } from "../util";
function SquareItemCard({ item, ...props }) { function SquareItemCard({ item, ...props }) {
const theme = useTheme(); const outlineShadowValue = useToken("shadows", "outline");
return ( return (
<ClassNames> <ClassNames>
@ -23,7 +28,7 @@ function SquareItemCard({ item, ...props }) {
transform: scale(1.05); transform: scale(1.05);
} }
&:focus { &:focus {
box-shadow: ${theme.shadows.outline}; box-shadow: ${outlineShadowValue};
outline: none; outline: none;
} }
`} `}
@ -31,23 +36,7 @@ function SquareItemCard({ item, ...props }) {
> >
<SquareItemCardLayout <SquareItemCardLayout
name={item.name} name={item.name}
thumbnailImage={ thumbnailImage={<ItemThumbnail item={item} />}
<img
src={safeImageUrl(item.thumbnailUrl)}
alt={`Thumbnail art for ${item.name}`}
width={80}
height={80}
className={css`
border-radius: ${theme.radii.md};
/* Don't let alt text flash in while loading */
&:-moz-loading {
visibility: hidden;
}
`}
loading="lazy"
/>
}
/> />
</Link> </Link>
)} )}
@ -103,6 +92,81 @@ function SquareItemCardLayout({ name, thumbnailImage, minHeightNumLines = 2 }) {
); );
} }
function ItemThumbnail({ item }) {
const mdRadiusValue = useToken("radii", "md");
const badgeBackground = useColorModeValue(
item.isNc ? "purple.100" : "gray.100",
item.isNc ? "purple.500" : "gray.500"
);
const badgeColor = useColorModeValue(
item.isNc ? "purple.500" : "gray.500",
item.isNc ? "purple.100" : "gray.100"
);
const thumbnailShadowColor = useColorModeValue(
item.isNc ? "purple.200" : "gray.200",
item.isNc ? "purple.600" : "gray.600"
);
const [
badgeBackgroundValue,
badgeColorValue,
thumbnailShadowColorValue,
] = useToken("colors", [badgeBackground, badgeColor, thumbnailShadowColor]);
return (
<ClassNames>
{({ css }) => (
<div
className={css`
position: relative;
`}
>
<img
src={safeImageUrl(item.thumbnailUrl)}
alt={`Thumbnail art for ${item.name}`}
width={80}
height={80}
className={css`
border-radius: ${mdRadiusValue};
box-shadow: 0 0 4px ${thumbnailShadowColorValue};
/* Don't let alt text flash in while loading */
&:-moz-loading {
visibility: hidden;
}
`}
loading="lazy"
/>
{item.isNc != null && (
<div
className={css`
position: absolute;
bottom: -6px;
right: -3px;
/* Copied from Chakra <Badge> */
display: inline-block;
white-space: nowrap;
vertical-align: middle;
padding-left: 0.25rem;
padding-right: 0.25rem;
text-transform: uppercase;
font-size: 0.65rem;
border-radius: 0.125rem;
font-weight: 700;
background: ${badgeBackgroundValue};
color: ${badgeColorValue};
`}
>
{item.isNc ? "NC" : "NP"}
</div>
)}
</div>
)}
</ClassNames>
);
}
export function SquareItemCardSkeleton({ minHeightNumLines }) { export function SquareItemCardSkeleton({ minHeightNumLines }) {
return ( return (
<SquareItemCardLayout <SquareItemCardLayout