Skip to content

Commit 60b09fb

Browse files
Greg HoskinGreg Hoskin
Greg Hoskin
authored and
Greg Hoskin
committed
image, cart item, type fixes
1 parent 7ac72a2 commit 60b09fb

File tree

11 files changed

+37
-44
lines changed

11 files changed

+37
-44
lines changed

assets/components.css

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
.fit {
22
min-height: calc(100vh - 88px);
33
}
4+
5+
input::-webkit-outer-spin-button,
6+
input::-webkit-inner-spin-button {
7+
-webkit-appearance: none;
8+
margin: 0;
9+
}
10+
11+
input[type=number] {
12+
-moz-appearance: textfield;
13+
}

blocks/ProductGrid/ProductGrid.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LoadingDots } from '@components/ui'
66
import { Grid } from '@theme-ui/components'
77
import { ProductCardProps } from '@components/common/ProductCard'
88
import { ProductCardDemo, ProductCard } from '@components/common'
9+
import { Product } from '@lib/swell/storefront-data-hooks/src/types'
910

1011
import {
1112
getCollection,
@@ -46,10 +47,11 @@ export const ProductGrid: FC<ProductGridProps> = ({
4647
.filter((handle: string | undefined) => typeof handle === 'string')
4748
.map(
4849
async (handle: string) => {
49-
return await getProduct(builderConfig, { slug: handle })
50+
return await getProduct({ slug: handle })
5051
}
5152
)
52-
setProducts(await Promise.all(promises))
53+
const result = await Promise.all(promises)
54+
setProducts(result)
5355
setLoading(false)
5456
}
5557
if (productsList && !initialProducts) {

blocks/ProductView/ProductLoader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ProductLoader: React.FC<Props> = ({
2424
useEffect(() => {
2525
const fetchProduct = async () => {
2626
setLoading(true)
27-
const result = await getProduct(builderConfig, {
27+
const result = await getProduct({
2828
slug: String(product),
2929
})
3030
setProduct(result)

blocks/ProductView/ProductView.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ import {
1414
} from '@lib/swell/storefront-data-hooks/src/utils/product'
1515
import { ImageCarousel, LoadingDots } from '@components/ui'
1616
import ProductLoader from './ProductLoader'
17-
import { OptionInput, OptionValue, ProductOption, Product, ProductProps } from '@lib/swell/storefront-data-hooks/src/types'
17+
import { OptionInput, OptionValue, ProductOption, Product } from '@lib/swell/storefront-data-hooks/src/types'
18+
19+
export interface ProductProps {
20+
className?: string
21+
children?: any
22+
product: Product
23+
renderSeo?: boolean
24+
description?: string
25+
title?: string
26+
}
27+
1828

1929
const ProductBox: React.FC<ProductProps> = ({
2030
product,

components/common/ProductCard.tsx

+3-21
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,12 @@ import { Themed, jsx } from 'theme-ui'
44
import { Card, Text } from '@theme-ui/components'
55
import { Link, ImageCarousel } from '@components/ui'
66
import { getPrice } from '@lib/swell/storefront-data-hooks/src/utils/product'
7-
import { useState } from 'react'
7+
import { Product } from '@lib/swell/storefront-data-hooks/src/types'
88

9-
type SwellProductOption = {
10-
id: string
11-
name: string
12-
values: any[]
13-
}
14-
15-
export interface SwellProduct {
16-
id: string
17-
description: string
18-
name: string
19-
slug: string
20-
currency: string
21-
price: number
22-
images: any[]
23-
options: SwellProductOption[]
24-
variants: any[]
25-
}
269

2710
export interface ProductCardProps {
2811
className?: string
29-
product: SwellProduct
12+
product: Product
3013
imgWidth: number | string
3114
imgHeight: number | string
3215
imgLayout?: 'fixed' | 'intrinsic' | 'responsive' | undefined
@@ -44,8 +27,7 @@ const ProductCard: React.FC<ProductCardProps> = ({
4427
imgSizes,
4528
imgLayout = 'responsive',
4629
}) => {
47-
const handle = (product as any).slug
48-
30+
const handle = (product).slug
4931
const price = getPrice(
5032
product.price,
5133
product.currency ?? 'USD'

components/common/ProductCardDemo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ProductCardDemo: React.FC<ProductCardProps> = ({
3737
productVariant.price,
3838
product.currency ?? 'USD'
3939
)
40-
const alternateImage = product.images[1]?.src
40+
const alternateImage = product.images[1]?.file.url
4141

4242
return (
4343
<Card

components/common/UntilInteraction.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const UntilInteraction: React.FC<{ skeleton: React.ReactNode }> = ({
1010
}
1111
return (
1212
<div
13-
onMouseOver={() => setRender(true)}
13+
// onMouseOver={() => setRender(true)}
1414
onClick={() => setRender(true)}
1515
onTouchStart={() => setRender(true)}
1616
>

lib/resolve-swell-content.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function resolveSwellContent(
3131
.filter((handle: string | undefined) => typeof handle === 'string')
3232
.map(
3333
async (handle: string) =>
34-
await getProduct(builderConfig, { slug: handle })
34+
await getProduct({ slug: handle })
3535
)
3636
products = await Promise.all(promises)
3737
}
@@ -55,7 +55,7 @@ export async function resolveSwellContent(
5555
async ProductBox(props) {
5656
let product = props.product
5757
if (product && typeof product === 'string') {
58-
product = await getProduct(builderConfig, {
58+
product = await getProduct({
5959
slug: product,
6060
})
6161
}

lib/swell/storefront-data-hooks/src/api/operations-swell.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export async function getAllProductPaths(
6363
return products?.map((entry: any) => entry.slug) || []
6464
}
6565

66-
export async function getProduct(builderConfig: any,
67-
options: { id?: string; slug?: string; withContent?: boolean }
66+
export async function getProduct(options: { id?: string; slug?: string; withContent?: boolean }
6867
) {
6968
await swell.init(swellConfig.storeId, swellConfig.publicKey)
7069
if (Boolean(options.id) === Boolean(options.slug)) {

lib/swell/storefront-data-hooks/src/types.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export type CartItem = {
4949
product: Product
5050
price: number
5151
variant: {
52-
name: string | null
53-
sku: string | null
52+
name?: string
53+
sku?: string
5454
id: string
5555
}
5656
quantity: number
@@ -94,13 +94,3 @@ export type ProductOption = {
9494
name: string
9595
values: OptionValue[]
9696
}
97-
98-
99-
export interface ProductProps {
100-
className?: string
101-
children?: any
102-
product: Product
103-
renderSeo?: boolean
104-
description?: string
105-
title?: string
106-
}

pages/product/[handle].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Builder.isStatic = true
2323
const builderModel = 'product-page'
2424

2525
export async function getStaticProps(context: GetStaticPropsContext<{ handle: string }>) {
26-
const product = await getProduct(builderConfig, {
26+
const product = await getProduct({
2727
slug: context.params?.handle,
2828
})
2929
const page = await resolveSwellContent(builderModel, {

0 commit comments

Comments
 (0)