Skip to content

Commit 86026d2

Browse files
committed
Add image placeholder support for single products
1 parent 7f2f3b1 commit 86026d2

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

components/Product/IndexProducts.component.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const IndexProducts = ({ products }) => {
4646
id="product-image"
4747
className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105"
4848
alt={name}
49-
src={WOO_CONFIG.PLACEHOLDER_IMAGE_URL}
49+
src={WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL}
5050
/>
5151
)}
5252
</a>

components/Product/SingleProduct.component.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { useState, useEffect } from 'react';
33
import AddToCartButton from 'components/Cart/AddToCartButton.component';
44
import LoadingSpinner from 'components/LoadingSpinner/LoadingSpinner.component';
55

6+
import { WOO_CONFIG } from 'utils/config/nextConfig';
7+
68
/**
79
* Shows a single product with an Add To Cart button.
810
* Uses GraphQL for product data
@@ -41,12 +43,22 @@ const SingleProduct = ({ product }) => {
4143
) : (
4244
<div className="container flex flex-wrap items-center pt-4 pb-12 mx-auto ">
4345
<div className="grid grid-cols-1 gap-4 mt-16 lg:grid-cols-2 xl:grid-cols-2 md:grid-cols-2 sm:grid-cols-2">
44-
<img
45-
id="product-image"
46-
className="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:grow hover:shadow-lg hover:scale-105"
47-
alt={name}
48-
src={image.sourceUrl}
49-
/>
46+
{image ? (
47+
<img
48+
id="product-image"
49+
className="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:grow hover:shadow-lg hover:scale-105"
50+
alt={name}
51+
src={image.sourceUrl}
52+
/>
53+
) : (
54+
<img
55+
id="product-image"
56+
className="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:grow hover:shadow-lg hover:scale-105"
57+
alt={name}
58+
src={WOO_CONFIG.PLACEHOLDER_LARGE_IMAGE_URL}
59+
/>
60+
)}
61+
5062
<div className="ml-8">
5163
<p className="text-3xl font-bold text-left">{name}</p>
5264
<br />

utils/config/nextConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const WOO_CONFIG = {
1919
ALGOLIA_APP_ID: '7L9M5Y0B1K',
2020
ALGOLIA_PUBLIC_API_KEY: '925cc92373120f1bf477bb8ce0e71649',
2121
ALGOLIA_INDEX_NAME: 'dfweb',
22-
PLACEHOLDER_IMAGE_URL: "https://via.placeholder.com/272",
22+
PLACEHOLDER_SMALL_IMAGE_URL: 'https://via.placeholder.com/272',
23+
PLACEHOLDER_LARGE_IMAGE_URL: 'https://via.placeholder.com/616',
2324
};
2425

25-
2626
export default WOO_CONFIG;

0 commit comments

Comments
 (0)