forked from crowetic/commerce
More profiles
This commit is contained in:
parent
12acdd596a
commit
0dad8ba839
@ -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();
|
||||
});
|
||||
}}
|
||||
|
@ -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();
|
||||
});
|
||||
}}
|
||||
|
@ -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();
|
||||
});
|
||||
}}
|
||||
|
@ -198,12 +198,12 @@ const reshapeProducts = (products: ShopifyProduct[]) => {
|
||||
};
|
||||
|
||||
export async function createCart(): Promise<Cart> {
|
||||
console.time('createCart');
|
||||
console.time('profile - create cart - api');
|
||||
const res = await shopifyFetch<ShopifyCreateCartOperation>({
|
||||
query: createCartMutation,
|
||||
cache: 'no-store'
|
||||
});
|
||||
console.timeEnd('createCart');
|
||||
console.timeEnd('profile - create cart - api');
|
||||
return reshapeCart(res.body.data.cartCreate.cart);
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ export async function addToCart(
|
||||
cartId: string,
|
||||
lines: { merchandiseId: string; quantity: number }[]
|
||||
): Promise<Cart> {
|
||||
console.time('addToCart');
|
||||
console.time('profile - add to cart - api');
|
||||
const res = await shopifyFetch<ShopifyAddToCartOperation>({
|
||||
query: addToCartMutation,
|
||||
variables: {
|
||||
@ -220,12 +220,12 @@ export async function addToCart(
|
||||
},
|
||||
cache: 'no-store'
|
||||
});
|
||||
console.timeEnd('addToCart');
|
||||
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('removeFromCart');
|
||||
console.time('profile - remove from cart - api');
|
||||
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({
|
||||
query: removeFromCartMutation,
|
||||
variables: {
|
||||
@ -234,7 +234,7 @@ export async function removeFromCart(cartId: string, lineIds: string[]): Promise
|
||||
},
|
||||
cache: 'no-store'
|
||||
});
|
||||
console.timeEnd('removeFromCart');
|
||||
console.timeEnd('profile - remove from cart - api');
|
||||
return reshapeCart(res.body.data.cartLinesRemove.cart);
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ export async function updateCart(
|
||||
cartId: string,
|
||||
lines: { id: string; merchandiseId: string; quantity: number }[]
|
||||
): Promise<Cart> {
|
||||
console.time('updateCart');
|
||||
console.time('profile - update cart - api');
|
||||
const res = await shopifyFetch<ShopifyUpdateCartOperation>({
|
||||
query: editCartItemsMutation,
|
||||
variables: {
|
||||
@ -251,7 +251,7 @@ export async function updateCart(
|
||||
},
|
||||
cache: 'no-store'
|
||||
});
|
||||
console.timeEnd('updateCart');
|
||||
console.timeEnd('profile - update cart - api');
|
||||
return reshapeCart(res.body.data.cartLinesUpdate.cart);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user