Skip to content

Commit

Permalink
Merge pull request #241 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Update production.
  • Loading branch information
mathewjordan authored Feb 15, 2023
2 parents e30e627 + f0e2c08 commit 1e8e4e6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
17 changes: 15 additions & 2 deletions components/Figure/Figure.styled.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import * as AspectRatio from "@radix-ui/react-aspect-ratio";
import { VariantProps, styled } from "@/stitches.config";
import { IconLock } from "@/components/Shared/SVG/Icons";
import Image from "next/image";

/* eslint sort-keys: 0 */

IconLock.toString = () => ".icon-lock";

const FigureImage = styled("img", {
const FigureImage = styled(Image, {
display: "flex",
borderRadius: "3px",
transition: "$dcAll",
transition: "$dcImageLoad",
opacity: "0",
width: "100%",
height: "100%",
objectFit: "cover",
zIndex: "1",

variants: {
isLoaded: {
Expand All @@ -27,6 +29,15 @@ const FigureImage = styled("img", {
},
});

const FigureLQIP = styled(Image, {
display: "flex",
borderRadius: "3px",
width: "100%",
height: "100%",
objectFit: "cover",
zIndex: "0",
});

const FigureImageWrapper = styled("div", {
display: "flex",
flexDirection: "column",
Expand Down Expand Up @@ -62,6 +73,7 @@ const FigureCaption = styled("figcaption", {
const FigurePlaceholder = styled(AspectRatio.Root, {
backgroundColor: "$black10",
borderRadius: "3px",
zIndex: "0",
});

const FigureSupplementalInfo = styled("span", {
Expand Down Expand Up @@ -123,6 +135,7 @@ export {
FigureCaption,
FigureImage,
FigureImageWrapper,
FigureLQIP,
FigurePlaceholder,
FigureStyled,
FigureSupplementalInfo,
Expand Down
28 changes: 19 additions & 9 deletions components/Figure/Figure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
FigureCaption,
FigureImage,
FigureImageWrapper,
FigureLQIP,
FigurePlaceholder,
FigureStyled,
FigureSupplementalInfo,
Expand All @@ -11,6 +12,7 @@ import {
} from "@/components/Figure/Figure.styled";
import React, { ReactNode } from "react";
import { IconLock } from "@/components/Shared/SVG/Icons";
import { width } from "@/styles/media";

interface Figure {
aspectRatio?: number;
Expand All @@ -31,25 +33,33 @@ const Figure: React.FC<FigureProps & FigureVariants> = (props) => {
const { data, orientation } = props;
const { aspectRatio, isRestricted, title, supplementalInfo, src } = data;

const handleOnLoad = () => {
setIsLoaded(true);
};
const handleOnLoad = () => setIsLoaded(true);
const handleOnError = () => console.error("image loading error");

const handleOnError = () => {
console.error("image loading error");
};
const lqip = new URL(src);
lqip.searchParams.set("size", "3");

const srcSetSizes = `(max-width: ${width.xxs}px) 100vw`;

return (
<FigureStyled data-orientation={orientation} {...props}>
<FigureImageWrapper>
<FigurePlaceholder ratio={aspectRatio ? aspectRatio : 1}>
<FigureLQIP
alt=""
fill={true}
sizes={srcSetSizes}
src={lqip.toString()}
priority={true}
/>
<FigureImage
src={src}
alt={title}
fill={true}
isLoaded={isLoaded}
onLoad={handleOnLoad}
onError={handleOnError}
isLoaded={isLoaded}
{...(isRestricted && { css: { opacity: "0.7" } })}
sizes={srcSetSizes}
src={src}
/>
</FigurePlaceholder>
</FigureImageWrapper>
Expand Down
20 changes: 10 additions & 10 deletions components/Grid/Item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ describe("GridItem component", () => {
it("renders the expected default image source", () => {
render(<GridItem item={mockItem as SearchShape} />);

expect(screen.getByAltText(mockItem.title)).toHaveAttribute(
"src",
mockItem.thumbnail
expect(screen.getByAltText(mockItem.title).getAttribute("src")).toContain(
encodeURIComponent(mockItem.thumbnail)
);
});

it("renders the full resolution image source is featured", () => {
render(<GridItem item={mockItem as SearchShape} isFeatured />);

expect(screen.getByAltText(mockItem.title)).not.toHaveAttribute(
"src",
mockItem.thumbnail
);
expect(screen.getByAltText(mockItem.title)).toHaveAttribute(
"src",
"https://iiif.stack.rdc-staging.library.northwestern.edu/iiif/2/b92874a0-72b7-4479-979e-38860c412a13/square/512,/0/default.jpg"
expect(
screen.getByAltText(mockItem.title).getAttribute("src")
).not.toContain(encodeURIComponent(mockItem.thumbnail));

expect(screen.getByAltText(mockItem.title).getAttribute("src")).toContain(
encodeURIComponent(
"https://iiif.stack.rdc-staging.library.northwestern.edu/iiif/2/b92874a0-72b7-4479-979e-38860c412a13/square/512,/0/default.jpg"
)
);
});
});
5 changes: 1 addition & 4 deletions components/Grid/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface GridItemProps {

const GridItem: React.FC<GridItemProps> = ({ item, isFeatured }) => {
const [urlPath, setUrlPath] = useState<string>();
const [supplementalInfo, setSupplementalInfo] = useState<string | null>();
const userContext = useContext(UserContext);

const isRestricted = (item: SearchShape): boolean => {
Expand All @@ -25,14 +24,12 @@ const GridItem: React.FC<GridItemProps> = ({ item, isFeatured }) => {
switch (item.api_model) {
case "Work":
setUrlPath("/items");
setSupplementalInfo(item.work_type);
return;
case "Collection":
setUrlPath("/collections");
return;
default:
setUrlPath("/items");
setSupplementalInfo(item.work_type);
return;
}
}, [item]);
Expand All @@ -48,7 +45,7 @@ const GridItem: React.FC<GridItemProps> = ({ item, isFeatured }) => {
isFeatured && item.representative_file_set?.url
? `${item.representative_file_set.url}/square/512,/0/default.jpg`
: item.thumbnail || "",
supplementalInfo: supplementalInfo,
supplementalInfo: item.work_type,
title: item.title || "",
}}
/>
Expand Down
6 changes: 6 additions & 0 deletions lib/constants/works.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const WORK_METADATA_LABELS: WorkMetadata[] = [
label: "Department",
searchParam: "libraryDepartment",
},
{
label: "Dimensions",
},
{
label: "Genre",
searchParam: "genre",
Expand All @@ -42,6 +45,9 @@ const WORK_METADATA_LABELS: WorkMetadata[] = [
{
label: "Location",
},
{
label: "Materials",
},
{
label: "Notes",
},
Expand Down
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module.exports = {
"dcapi.rdc.library.northwestern.edu",
"dcapi.rdc-staging.library.northwestern.edu",
"iiif.stack.rdc.library.northwestern.edu",
"iiif.dc.library.northwestern.edu",
"api.dc.library.northwestern.edu",
],
},
reactStrictMode: true,
Expand Down
1 change: 1 addition & 0 deletions styles/transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const timingFunction = `cubic-bezier(0.3, 1, 0.3, 1)`;
const transitions = {
dcAll: `all ${seconds}s ${timingFunction}`,
dcOpacity: `opacity ${seconds}s ${timingFunction}`,
dcImageLoad: `all 1s ${timingFunction}`,
dcWidth: `width ${seconds}s ${timingFunction}`,
};

Expand Down

0 comments on commit 1e8e4e6

Please sign in to comment.