Make image, variant, and cart updates faster with useOptimistic (#1365)

This commit is contained in:
Lee Robinson
2024-07-28 22:58:59 -05:00
committed by GitHub
parent dd7449f975
commit 9a4c995bb6
24 changed files with 642 additions and 382 deletions

View File

@@ -254,12 +254,15 @@ export async function updateCart(
return reshapeCart(res.body.data.cartLinesUpdate.cart);
}
export async function getCart(cartId: string): Promise<Cart | undefined> {
export async function getCart(cartId: string | undefined): Promise<Cart | undefined> {
if (!cartId) {
return undefined;
}
const res = await shopifyFetch<ShopifyCartOperation>({
query: getCartQuery,
variables: { cartId },
tags: [TAGS.cart],
cache: 'no-store'
tags: [TAGS.cart]
});
// Old carts becomes `null` when you checkout.

View File

@@ -12,8 +12,15 @@ export type Cart = Omit<ShopifyCart, 'lines'> & {
lines: CartItem[];
};
export type CartItem = {
export type CartProduct = {
id: string;
handle: string;
title: string;
featuredImage: Image;
};
export type CartItem = {
id: string | undefined;
quantity: number;
cost: {
totalAmount: Money;
@@ -25,7 +32,7 @@ export type CartItem = {
name: string;
value: string;
}[];
product: Product;
product: CartProduct;
};
};
@@ -89,7 +96,7 @@ export type SEO = {
};
export type ShopifyCart = {
id: string;
id: string | undefined;
checkoutUrl: string;
cost: {
subtotalAmount: Money;