Skip to content

Commit

Permalink
rebuild the color picker using colorType
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkevingreen committed Sep 4, 2023
1 parent 383226b commit 1680c3c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
20 changes: 13 additions & 7 deletions app/queries/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,23 @@ const productQuery = groq`
...,
variants[]-> {
...,
'pattern': pattern[0] {
'pattern': pattern-> {
_type,
_key,
_type == 'color' => {
'color': hex,
},
_type == 'image' => {
'image': asset-> {
...
...,
'colorType': colorType[0] {
_type,
_key,
_type == 'color' => {
'color': hex,
},
_type == 'module.image' => {
'image': image.asset-> {
...
}
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/routes/($locale).products.$handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const loader = async ({ params, context, request }) => {
}

const sanityProduct = await context.sanity.fetch(QUERY_PRODUCT(handle))

const selectedVariant = product.selectedVariant ?? product?.variants?.nodes[0]

return json({
Expand Down Expand Up @@ -174,16 +173,17 @@ export default function ProductHandle() {
const matchedPattern = sanityProduct.store.variants.find(variant => {
return variant.store.title == value
})
console.log('matchedPattern', matchedPattern.pattern.colorType)
optionParams.set(name, value)
return (
/* Use the `active` state to conditionally style the active item. */
<Link
key={value}
preventScrollReset
style={{
backgroundImage: matchedPattern.pattern?.image ? `url(${matchedPattern.pattern?.image?.url})` : 'none',
backgroundImage: matchedPattern.pattern?.colorType?.image ? `url(${matchedPattern.pattern?.colorType?.image?.url})` : 'none',
backgroundSize: 'cover',
backgroundColor: matchedPattern.pattern?.color,
backgroundColor: matchedPattern.pattern?.colorType?.color,
}}
aria-label={`${name}: ${value}`}
to={`${pathname}?${optionParams.toString()}`}
Expand Down
13 changes: 2 additions & 11 deletions cms/schemas/documents/productVariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,9 @@ export default defineType({
defineField({
title: 'Pattern',
name: 'pattern',
type: 'array',
type: 'reference',
to: { type: 'colorType' },
group: 'editorial',
of: [{
type: 'color',
name: 'color',
title: 'Color'
}, {
type: 'image',
name: 'image',
title: 'Image'
}],
validation: Rule => Rule.required().max(1),
}),
// Shopify product variant
defineField({
Expand Down
31 changes: 16 additions & 15 deletions cms/schemas/objects/shopifyProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ export default defineField({
},
],
fields: [
// Variants
defineField({
fieldset: 'variants',
name: 'variants',
title: 'Variants',
type: 'array',
of: [
{
title: 'Variant',
type: 'reference',
weak: true,
to: [{type: 'productVariant'}],
},
],
}),
// Created at
defineField({
fieldset: 'status',
Expand Down Expand Up @@ -194,20 +209,6 @@ export default defineField({
},
],
}),
// Variants
defineField({
fieldset: 'variants',
name: 'variants',
title: 'Variants',
type: 'array',
of: [
{
title: 'Variant',
type: 'reference',
weak: true,
to: [{type: 'productVariant'}],
},
],
}),

],
})

0 comments on commit 1680c3c

Please sign in to comment.