Skip to content

Commit 1e8e4e6

Browse files
authored
Merge pull request #241 from nulib/deploy/staging
Update production.
2 parents e30e627 + f0e2c08 commit 1e8e4e6

File tree

7 files changed

+54
-25
lines changed

7 files changed

+54
-25
lines changed

components/Figure/Figure.styled.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import * as AspectRatio from "@radix-ui/react-aspect-ratio";
22
import { VariantProps, styled } from "@/stitches.config";
33
import { IconLock } from "@/components/Shared/SVG/Icons";
4+
import Image from "next/image";
45

56
/* eslint sort-keys: 0 */
67

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

9-
const FigureImage = styled("img", {
10+
const FigureImage = styled(Image, {
1011
display: "flex",
1112
borderRadius: "3px",
12-
transition: "$dcAll",
13+
transition: "$dcImageLoad",
1314
opacity: "0",
1415
width: "100%",
1516
height: "100%",
1617
objectFit: "cover",
18+
zIndex: "1",
1719

1820
variants: {
1921
isLoaded: {
@@ -27,6 +29,15 @@ const FigureImage = styled("img", {
2729
},
2830
});
2931

32+
const FigureLQIP = styled(Image, {
33+
display: "flex",
34+
borderRadius: "3px",
35+
width: "100%",
36+
height: "100%",
37+
objectFit: "cover",
38+
zIndex: "0",
39+
});
40+
3041
const FigureImageWrapper = styled("div", {
3142
display: "flex",
3243
flexDirection: "column",
@@ -62,6 +73,7 @@ const FigureCaption = styled("figcaption", {
6273
const FigurePlaceholder = styled(AspectRatio.Root, {
6374
backgroundColor: "$black10",
6475
borderRadius: "3px",
76+
zIndex: "0",
6577
});
6678

6779
const FigureSupplementalInfo = styled("span", {
@@ -123,6 +135,7 @@ export {
123135
FigureCaption,
124136
FigureImage,
125137
FigureImageWrapper,
138+
FigureLQIP,
126139
FigurePlaceholder,
127140
FigureStyled,
128141
FigureSupplementalInfo,

components/Figure/Figure.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
FigureCaption,
33
FigureImage,
44
FigureImageWrapper,
5+
FigureLQIP,
56
FigurePlaceholder,
67
FigureStyled,
78
FigureSupplementalInfo,
@@ -11,6 +12,7 @@ import {
1112
} from "@/components/Figure/Figure.styled";
1213
import React, { ReactNode } from "react";
1314
import { IconLock } from "@/components/Shared/SVG/Icons";
15+
import { width } from "@/styles/media";
1416

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

34-
const handleOnLoad = () => {
35-
setIsLoaded(true);
36-
};
36+
const handleOnLoad = () => setIsLoaded(true);
37+
const handleOnError = () => console.error("image loading error");
3738

38-
const handleOnError = () => {
39-
console.error("image loading error");
40-
};
39+
const lqip = new URL(src);
40+
lqip.searchParams.set("size", "3");
41+
42+
const srcSetSizes = `(max-width: ${width.xxs}px) 100vw`;
4143

4244
return (
4345
<FigureStyled data-orientation={orientation} {...props}>
4446
<FigureImageWrapper>
4547
<FigurePlaceholder ratio={aspectRatio ? aspectRatio : 1}>
48+
<FigureLQIP
49+
alt=""
50+
fill={true}
51+
sizes={srcSetSizes}
52+
src={lqip.toString()}
53+
priority={true}
54+
/>
4655
<FigureImage
47-
src={src}
4856
alt={title}
57+
fill={true}
58+
isLoaded={isLoaded}
4959
onLoad={handleOnLoad}
5060
onError={handleOnError}
51-
isLoaded={isLoaded}
52-
{...(isRestricted && { css: { opacity: "0.7" } })}
61+
sizes={srcSetSizes}
62+
src={src}
5363
/>
5464
</FigurePlaceholder>
5565
</FigureImageWrapper>

components/Grid/Item.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ describe("GridItem component", () => {
3434
it("renders the expected default image source", () => {
3535
render(<GridItem item={mockItem as SearchShape} />);
3636

37-
expect(screen.getByAltText(mockItem.title)).toHaveAttribute(
38-
"src",
39-
mockItem.thumbnail
37+
expect(screen.getByAltText(mockItem.title).getAttribute("src")).toContain(
38+
encodeURIComponent(mockItem.thumbnail)
4039
);
4140
});
4241

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

46-
expect(screen.getByAltText(mockItem.title)).not.toHaveAttribute(
47-
"src",
48-
mockItem.thumbnail
49-
);
50-
expect(screen.getByAltText(mockItem.title)).toHaveAttribute(
51-
"src",
52-
"https://iiif.stack.rdc-staging.library.northwestern.edu/iiif/2/b92874a0-72b7-4479-979e-38860c412a13/square/512,/0/default.jpg"
45+
expect(
46+
screen.getByAltText(mockItem.title).getAttribute("src")
47+
).not.toContain(encodeURIComponent(mockItem.thumbnail));
48+
49+
expect(screen.getByAltText(mockItem.title).getAttribute("src")).toContain(
50+
encodeURIComponent(
51+
"https://iiif.stack.rdc-staging.library.northwestern.edu/iiif/2/b92874a0-72b7-4479-979e-38860c412a13/square/512,/0/default.jpg"
52+
)
5353
);
5454
});
5555
});

components/Grid/Item.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface GridItemProps {
1212

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

1817
const isRestricted = (item: SearchShape): boolean => {
@@ -25,14 +24,12 @@ const GridItem: React.FC<GridItemProps> = ({ item, isFeatured }) => {
2524
switch (item.api_model) {
2625
case "Work":
2726
setUrlPath("/items");
28-
setSupplementalInfo(item.work_type);
2927
return;
3028
case "Collection":
3129
setUrlPath("/collections");
3230
return;
3331
default:
3432
setUrlPath("/items");
35-
setSupplementalInfo(item.work_type);
3633
return;
3734
}
3835
}, [item]);
@@ -48,7 +45,7 @@ const GridItem: React.FC<GridItemProps> = ({ item, isFeatured }) => {
4845
isFeatured && item.representative_file_set?.url
4946
? `${item.representative_file_set.url}/square/512,/0/default.jpg`
5047
: item.thumbnail || "",
51-
supplementalInfo: supplementalInfo,
48+
supplementalInfo: item.work_type,
5249
title: item.title || "",
5350
}}
5451
/>

lib/constants/works.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const WORK_METADATA_LABELS: WorkMetadata[] = [
2828
label: "Department",
2929
searchParam: "libraryDepartment",
3030
},
31+
{
32+
label: "Dimensions",
33+
},
3134
{
3235
label: "Genre",
3336
searchParam: "genre",
@@ -42,6 +45,9 @@ const WORK_METADATA_LABELS: WorkMetadata[] = [
4245
{
4346
label: "Location",
4447
},
48+
{
49+
label: "Materials",
50+
},
4551
{
4652
label: "Notes",
4753
},

next.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module.exports = {
3838
"dcapi.rdc.library.northwestern.edu",
3939
"dcapi.rdc-staging.library.northwestern.edu",
4040
"iiif.stack.rdc.library.northwestern.edu",
41+
"iiif.dc.library.northwestern.edu",
42+
"api.dc.library.northwestern.edu",
4143
],
4244
},
4345
reactStrictMode: true,

styles/transitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const timingFunction = `cubic-bezier(0.3, 1, 0.3, 1)`;
66
const transitions = {
77
dcAll: `all ${seconds}s ${timingFunction}`,
88
dcOpacity: `opacity ${seconds}s ${timingFunction}`,
9+
dcImageLoad: `all 1s ${timingFunction}`,
910
dcWidth: `width ${seconds}s ${timingFunction}`,
1011
};
1112

0 commit comments

Comments
 (0)