4
0
forked from crowetic/commerce

Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Novotny
0dad8ba839
More profiles 2023-08-02 09:43:38 -05:00
Michael Novotny
12acdd596a
Profiles cart 2023-08-02 09:32:33 -05:00
4 changed files with 14 additions and 6 deletions

View File

@ -37,6 +37,7 @@ export function AddToCart({
disabled={isPending || !availableForSale || !selectedVariantId}
title={title}
onClick={() => {
console.time('profile - add to cart - button');
// Safeguard in case someone messes with `disabled` in devtools.
if (!availableForSale || !selectedVariantId) return;
@ -47,7 +48,7 @@ export function AddToCart({
alert(error);
return;
}
console.timeEnd('profile - add to cart - button');
router.refresh();
});
}}

View File

@ -15,6 +15,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
<button
aria-label="Remove cart item"
onClick={() => {
console.time('profile - remove from cart - button');
startTransition(async () => {
const error = await removeItem(item.id);
@ -22,7 +23,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
alert(error);
return;
}
console.timeEnd('profile - remove from cart - button');
router.refresh();
});
}}

View File

@ -21,6 +21,7 @@ export default function EditItemQuantityButton({
<button
aria-label={type === 'plus' ? 'Increase item quantity' : 'Reduce item quantity'}
onClick={() => {
console.time('profile - update cart - button');
startTransition(async () => {
const error =
type === 'minus' && item.quantity - 1 === 0
@ -35,7 +36,7 @@ export default function EditItemQuantityButton({
alert(error);
return;
}
console.timeEnd('profile - update cart - button');
router.refresh();
});
}}

View File

@ -198,11 +198,12 @@ const reshapeProducts = (products: ShopifyProduct[]) => {
};
export async function createCart(): Promise<Cart> {
console.time('profile - create cart - api');
const res = await shopifyFetch<ShopifyCreateCartOperation>({
query: createCartMutation,
cache: 'no-store'
});
console.timeEnd('profile - create cart - api');
return reshapeCart(res.body.data.cartCreate.cart);
}
@ -210,6 +211,7 @@ export async function addToCart(
cartId: string,
lines: { merchandiseId: string; quantity: number }[]
): Promise<Cart> {
console.time('profile - add to cart - api');
const res = await shopifyFetch<ShopifyAddToCartOperation>({
query: addToCartMutation,
variables: {
@ -218,10 +220,12 @@ export async function addToCart(
},
cache: 'no-store'
});
console.timeEnd('profile - add to cart - api');
return reshapeCart(res.body.data.cartLinesAdd.cart);
}
export async function removeFromCart(cartId: string, lineIds: string[]): Promise<Cart> {
console.time('profile - remove from cart - api');
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({
query: removeFromCartMutation,
variables: {
@ -230,7 +234,7 @@ export async function removeFromCart(cartId: string, lineIds: string[]): Promise
},
cache: 'no-store'
});
console.timeEnd('profile - remove from cart - api');
return reshapeCart(res.body.data.cartLinesRemove.cart);
}
@ -238,6 +242,7 @@ export async function updateCart(
cartId: string,
lines: { id: string; merchandiseId: string; quantity: number }[]
): Promise<Cart> {
console.time('profile - update cart - api');
const res = await shopifyFetch<ShopifyUpdateCartOperation>({
query: editCartItemsMutation,
variables: {
@ -246,7 +251,7 @@ export async function updateCart(
},
cache: 'no-store'
});
console.timeEnd('profile - update cart - api');
return reshapeCart(res.body.data.cartLinesUpdate.cart);
}