mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 04:01:21 +00:00
add cache-buster to cart
This commit is contained in:
parent
0e7e7b7d5f
commit
7a34362456
@ -22,16 +22,21 @@ const CartItem = ({
|
|||||||
item,
|
item,
|
||||||
variant = 'default',
|
variant = 'default',
|
||||||
currencyCode,
|
currencyCode,
|
||||||
|
refreshCart,
|
||||||
...rest
|
...rest
|
||||||
}: {
|
}: {
|
||||||
variant?: 'default' | 'display'
|
variant?: 'default' | 'display'
|
||||||
item: LineItem
|
item: LineItem
|
||||||
currencyCode: string
|
currencyCode: string
|
||||||
|
refreshCart: () => void
|
||||||
}) => {
|
}) => {
|
||||||
const { closeSidebarIfPresent } = useUI()
|
const { closeSidebarIfPresent } = useUI()
|
||||||
const [removing, setRemoving] = useState(false)
|
const [removing, setRemoving] = useState(false)
|
||||||
const [quantity, setQuantity] = useState<number>(item.quantity)
|
const [quantity, setQuantity] = useState<number>(item.quantity)
|
||||||
const removeItem = useRemoveItem()
|
const removeItem = () => {
|
||||||
|
useRemoveItem()
|
||||||
|
refreshCart()
|
||||||
|
}
|
||||||
const updateItem = useUpdateItem({ item })
|
const updateItem = useUpdateItem({ item })
|
||||||
|
|
||||||
const { price } = usePrice({
|
const { price } = usePrice({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { FC } from 'react'
|
import { FC, useState, useCallback } from 'react'
|
||||||
import s from './CartSidebarView.module.css'
|
import s from './CartSidebarView.module.css'
|
||||||
import CartItem from '../CartItem'
|
import CartItem from '../CartItem'
|
||||||
import { Button, Text } from '@components/ui'
|
import { Button, Text } from '@components/ui'
|
||||||
@ -13,6 +13,11 @@ import SidebarLayout from '@components/common/SidebarLayout'
|
|||||||
const CartSidebarView: FC = () => {
|
const CartSidebarView: FC = () => {
|
||||||
const { closeSidebar, setSidebarView } = useUI()
|
const { closeSidebar, setSidebarView } = useUI()
|
||||||
const { data, isLoading, isEmpty } = useCart()
|
const { data, isLoading, isEmpty } = useCart()
|
||||||
|
const [lastChanged, setLastChanged] = useState(0)
|
||||||
|
|
||||||
|
const refreshCart = useCallback(() => setLastChanged(performance.now()), [
|
||||||
|
setLastChanged,
|
||||||
|
])
|
||||||
|
|
||||||
const { price: subTotal } = usePrice(
|
const { price: subTotal } = usePrice(
|
||||||
data && {
|
data && {
|
||||||
@ -38,6 +43,7 @@ const CartSidebarView: FC = () => {
|
|||||||
[s.empty]: error || success || isLoading || isEmpty,
|
[s.empty]: error || success || isLoading || isEmpty,
|
||||||
})}
|
})}
|
||||||
handleClose={handleClose}
|
handleClose={handleClose}
|
||||||
|
key={lastChanged}
|
||||||
>
|
>
|
||||||
{isLoading || isEmpty ? (
|
{isLoading || isEmpty ? (
|
||||||
<div className="flex-1 px-4 flex flex-col justify-center items-center">
|
<div className="flex-1 px-4 flex flex-col justify-center items-center">
|
||||||
@ -84,6 +90,7 @@ const CartSidebarView: FC = () => {
|
|||||||
key={item.id}
|
key={item.id}
|
||||||
item={item}
|
item={item}
|
||||||
currencyCode={data!.currency.code}
|
currencyCode={data!.currency.code}
|
||||||
|
refreshCart={refreshCart}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user