Skip to content

Commit 7f2f3b1

Browse files
committed
Add placeholder image for when product has no image
1 parent 3fb2b71 commit 7f2f3b1

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

components/Product/IndexProducts.component.jsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Link from 'next/link';
22
import { v4 as uuidv4 } from 'uuid';
33

4+
import { WOO_CONFIG } from 'utils/config/nextConfig';
5+
46
/**
57
* Displays all of the products as long as length is defined.
68
* Does a map() over the props array and utilizes uuidv4 for unique key values.
@@ -32,19 +34,36 @@ const IndexProducts = ({ products }) => {
3234
as={`/produkt/${slug}?productId=${productId}`}
3335
>
3436
<a>
35-
{image && (
37+
{image ? (
3638
<img
3739
id="product-image"
3840
className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105"
3941
alt={name}
4042
src={image.sourceUrl}
4143
/>
44+
) : (
45+
<img
46+
id="product-image"
47+
className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105"
48+
alt={name}
49+
src={WOO_CONFIG.PLACEHOLDER_IMAGE_URL}
50+
/>
4251
)}
4352
</a>
4453
</Link>
45-
<div className="flex justify-center pt-3">
46-
<p className="font-bold text-center">{name}</p>
47-
</div>
54+
<Link
55+
href="/produkt/[post]"
56+
as={`/produkt/${slug}?productId=${productId}`}
57+
>
58+
<a>
59+
<div className="flex justify-center pt-3">
60+
<p className="font-bold text-center cursor-pointer">
61+
{name}
62+
</p>
63+
</div>
64+
</a>
65+
</Link>
66+
4867
{/* Display sale price when on sale */}
4968
{onSale && (
5069
<>

utils/config/nextConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const WOO_CONFIG = {
88
ALGOLIA_APP_ID: '7L9M5Y0B1K',
99
ALGOLIA_PUBLIC_API_KEY: '925cc92373120f1bf477bb8ce0e71649',
1010
ALGOLIA_INDEX_NAME: 'dfweb',
11+
PLACEHOLDER_IMAGE_URL: "https://via.placeholder.com/272",
1112
};
1213
*/
1314

@@ -18,6 +19,7 @@ export const WOO_CONFIG = {
1819
ALGOLIA_APP_ID: '7L9M5Y0B1K',
1920
ALGOLIA_PUBLIC_API_KEY: '925cc92373120f1bf477bb8ce0e71649',
2021
ALGOLIA_INDEX_NAME: 'dfweb',
22+
PLACEHOLDER_IMAGE_URL: "https://via.placeholder.com/272",
2123
};
2224

2325

utils/const/GQL_QUERIES.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ export const GET_SINGLE_PRODUCT = gql`
3434
}
3535
}
3636
variations {
37-
nodes {
38-
id
39-
variationId
40-
name
41-
stockStatus
42-
stockQuantity
43-
purchasable
44-
onSale
45-
salePrice
46-
regularPrice
37+
nodes {
38+
id
39+
variationId
40+
name
41+
stockStatus
42+
stockQuantity
43+
purchasable
44+
onSale
45+
salePrice
46+
regularPrice
47+
}
4748
}
4849
}
49-
}
5050
... on ExternalProduct {
5151
price
5252
id
@@ -98,11 +98,11 @@ export const FETCH_FIRST_PRODUCTS_FROM_HOODIES_QUERY = `
9898
`;
9999

100100
/**
101-
* Fetch all Woocommerce products from GraphQL
101+
* Fetch first 24 Woocommerce products from GraphQL
102102
*/
103103
export const FETCH_ALL_PRODUCTS_QUERY = gql`
104104
query MyQuery {
105-
products(first: 8) {
105+
products(first: 24) {
106106
nodes {
107107
productId
108108
name
@@ -127,11 +127,11 @@ export const FETCH_ALL_PRODUCTS_QUERY = gql`
127127
`;
128128

129129
/**
130-
* Fetch all categories from GraphQL
130+
* Fetch first 20 categories from GraphQL
131131
*/
132132
export const FETCH_ALL_CATEGORIES_QUERY = gql`
133133
query Categories {
134-
productCategories(first: 10) {
134+
productCategories(first: 20) {
135135
nodes {
136136
id
137137
name

0 commit comments

Comments
 (0)