forked from crowetic/commerce
Compare commits
2 Commits
main
...
profile-ca
Author | SHA1 | Date | |
---|---|---|---|
|
0dad8ba839 | ||
|
12acdd596a |
@ -37,6 +37,7 @@ export function AddToCart({
|
|||||||
disabled={isPending || !availableForSale || !selectedVariantId}
|
disabled={isPending || !availableForSale || !selectedVariantId}
|
||||||
title={title}
|
title={title}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
console.time('profile - add to cart - button');
|
||||||
// Safeguard in case someone messes with `disabled` in devtools.
|
// Safeguard in case someone messes with `disabled` in devtools.
|
||||||
if (!availableForSale || !selectedVariantId) return;
|
if (!availableForSale || !selectedVariantId) return;
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ export function AddToCart({
|
|||||||
alert(error);
|
alert(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.timeEnd('profile - add to cart - button');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -15,6 +15,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
|
|||||||
<button
|
<button
|
||||||
aria-label="Remove cart item"
|
aria-label="Remove cart item"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
console.time('profile - remove from cart - button');
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
const error = await removeItem(item.id);
|
const error = await removeItem(item.id);
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
|
|||||||
alert(error);
|
alert(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.timeEnd('profile - remove from cart - button');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -21,6 +21,7 @@ export default function EditItemQuantityButton({
|
|||||||
<button
|
<button
|
||||||
aria-label={type === 'plus' ? 'Increase item quantity' : 'Reduce item quantity'}
|
aria-label={type === 'plus' ? 'Increase item quantity' : 'Reduce item quantity'}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
console.time('profile - update cart - button');
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
const error =
|
const error =
|
||||||
type === 'minus' && item.quantity - 1 === 0
|
type === 'minus' && item.quantity - 1 === 0
|
||||||
@ -35,7 +36,7 @@ export default function EditItemQuantityButton({
|
|||||||
alert(error);
|
alert(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.timeEnd('profile - update cart - button');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -198,11 +198,12 @@ const reshapeProducts = (products: ShopifyProduct[]) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function createCart(): Promise<Cart> {
|
export async function createCart(): Promise<Cart> {
|
||||||
|
console.time('profile - create cart - api');
|
||||||
const res = await shopifyFetch<ShopifyCreateCartOperation>({
|
const res = await shopifyFetch<ShopifyCreateCartOperation>({
|
||||||
query: createCartMutation,
|
query: createCartMutation,
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
console.timeEnd('profile - create cart - api');
|
||||||
return reshapeCart(res.body.data.cartCreate.cart);
|
return reshapeCart(res.body.data.cartCreate.cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +211,7 @@ export async function addToCart(
|
|||||||
cartId: string,
|
cartId: string,
|
||||||
lines: { merchandiseId: string; quantity: number }[]
|
lines: { merchandiseId: string; quantity: number }[]
|
||||||
): Promise<Cart> {
|
): Promise<Cart> {
|
||||||
|
console.time('profile - add to cart - api');
|
||||||
const res = await shopifyFetch<ShopifyAddToCartOperation>({
|
const res = await shopifyFetch<ShopifyAddToCartOperation>({
|
||||||
query: addToCartMutation,
|
query: addToCartMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@ -218,10 +220,12 @@ export async function addToCart(
|
|||||||
},
|
},
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
console.timeEnd('profile - add to cart - api');
|
||||||
return reshapeCart(res.body.data.cartLinesAdd.cart);
|
return reshapeCart(res.body.data.cartLinesAdd.cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeFromCart(cartId: string, lineIds: string[]): Promise<Cart> {
|
export async function removeFromCart(cartId: string, lineIds: string[]): Promise<Cart> {
|
||||||
|
console.time('profile - remove from cart - api');
|
||||||
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({
|
const res = await shopifyFetch<ShopifyRemoveFromCartOperation>({
|
||||||
query: removeFromCartMutation,
|
query: removeFromCartMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@ -230,7 +234,7 @@ export async function removeFromCart(cartId: string, lineIds: string[]): Promise
|
|||||||
},
|
},
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
console.timeEnd('profile - remove from cart - api');
|
||||||
return reshapeCart(res.body.data.cartLinesRemove.cart);
|
return reshapeCart(res.body.data.cartLinesRemove.cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +242,7 @@ export async function updateCart(
|
|||||||
cartId: string,
|
cartId: string,
|
||||||
lines: { id: string; merchandiseId: string; quantity: number }[]
|
lines: { id: string; merchandiseId: string; quantity: number }[]
|
||||||
): Promise<Cart> {
|
): Promise<Cart> {
|
||||||
|
console.time('profile - update cart - api');
|
||||||
const res = await shopifyFetch<ShopifyUpdateCartOperation>({
|
const res = await shopifyFetch<ShopifyUpdateCartOperation>({
|
||||||
query: editCartItemsMutation,
|
query: editCartItemsMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@ -246,7 +251,7 @@ export async function updateCart(
|
|||||||
},
|
},
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
console.timeEnd('profile - update cart - api');
|
||||||
return reshapeCart(res.body.data.cartLinesUpdate.cart);
|
return reshapeCart(res.body.data.cartLinesUpdate.cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user