From 34406394c8fb45eaf64b1dedae01aa5454da20a6 Mon Sep 17 00:00:00 2001 From: Benjamin Sehl Date: Wed, 1 Jun 2022 21:43:34 -0400 Subject: [PATCH] @benjaminsehl/pdp demo store neue (#1414) * Product Swimlane now works with product recommendations * Updates Header for mobile * Mobile layout for header, footer, and key layout components * Adds expanding menus to footer * Adds mobile layout for search * Basic product page layout * Adds URL param control to PDP --- .../sections/ProductForm.client.jsx | 36 +++++++++++++++++-- .../sections/ProductGallery.client.jsx | 34 +++++++----------- .../src/components/sections/Section.jsx | 3 +- .../src/routes/products/[handle].server.jsx | 22 ++++++++---- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/templates/demo-store-neue/src/components/sections/ProductForm.client.jsx b/templates/demo-store-neue/src/components/sections/ProductForm.client.jsx index 909087e3a0..e6c54b786a 100644 --- a/templates/demo-store-neue/src/components/sections/ProductForm.client.jsx +++ b/templates/demo-store-neue/src/components/sections/ProductForm.client.jsx @@ -1,8 +1,40 @@ -import {useProduct} from '@shopify/hydrogen'; +import {useEffect} from 'react'; +import {useProduct, useUrl, useNavigate} from '@shopify/hydrogen'; import {Heading, Text} from '~/components/elements'; export default function ProductForm() { + const {pathname, search} = useUrl(); + const navigate = useNavigate(); + + let params = new URLSearchParams(search); + const {options, setSelectedOption, selectedOptions} = useProduct(); + + useEffect(() => { + options.map(({name, values}) => { + const currentValue = params.get(name.toLowerCase()); + if (currentValue) { + const matchedValue = values.filter( + (value) => value.toLowerCase() === currentValue, + ); + setSelectedOption(name, matchedValue[0]); + } + }); + }, []); + + function handleChange(name, value) { + setSelectedOption(name, value); + params.set( + encodeURIComponent(name.toLowerCase()), + encodeURIComponent(value.toLowerCase()), + ); + navigate( + `${pathname}?${params.toString()}`, + {replace: true}, + {reloadDocument: false}, + ); + } + return (
{ @@ -27,7 +59,7 @@ export default function ProductForm() { name={`option[${name}]`} value={value} checked={checked} - onChange={() => setSelectedOption(name, value)} + onChange={() => handleChange(name, value)} />
- {mediaFiles.map((med) => { +
+ {media.map((med, i) => { let extraProps = {}; if (med.mediaContentType === 'MODEL_3D') { @@ -43,16 +32,19 @@ export default function Gallery() { }; return ( -
+
- -
- {product.title} - {product.vendor && {product.vendor}} - -
-
+
+
+ +
+ {product.title} + {product.vendor && ( + + {product.vendor} + + )} + +
+
+
+