Skip to content

Commit c30a383

Browse files
committed
fix: Refactor cart item controls and update quantity label
Simplifies cart item quantity controls in Cart.vue by consolidating increment/decrement and remove actions into a single UI element. Removes unused removeFromCart logic from useCart composable. Updates 'Qty' to 'Quantity' in English locale for clarity.
1 parent 471bd57 commit c30a383

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

app/components/Cart.vue

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--app/components/Cart.vue-->
22
<script setup>
3-
const { cart, handleRemoveFromCart, removeFromCartButtonStatus, increment, decrement } = useCart();
3+
const { cart, increment, decrement } = useCart();
44
const { order } = useCheckout();
55
</script>
66

@@ -26,27 +26,26 @@ const { order } = useCheckout();
2626
<p class="text-alizarin-crimson-700">-{{ ((1 - product.variation.node.salePrice / product.variation.node.regularPrice) * 100).toFixed(0) }}%</p>
2727
</div>
2828
<div class="text-xs flex gap-2 font-medium text-neutral-600 dark:text-neutral-300">
29-
<div>{{ $t('product.size') }}: {{ product.variation.attributes.map(attr => attr.value.toUpperCase()).join(', ') }} • {{ $t('product.quantity') }}:</div>
30-
<div class="flex items-center gap-1">
31-
<UIcon
32-
name="iconamoon:sign-minus-circle-fill"
33-
size="14"
34-
class="text-black dark:text-white cursor-pointer"
35-
@click="decrement(product.variation.node.databaseId)" />
36-
<span class="text-center">{{ product.quantity }}</span>
37-
<UIcon
38-
name="iconamoon:sign-plus-circle-fill"
39-
size="14"
40-
class="text-black dark:text-white cursor-pointer"
41-
@click="increment(product.variation.node.databaseId)" />
29+
<div>
30+
{{ $t('product.size') }}: {{ product.variation.attributes.map(attr => attr.value.toUpperCase()).join(', ') }} • {{ $t('product.quantity') }}:
31+
{{ product.quantity }}
4232
</div>
4333
</div>
4434
</div>
45-
<button
46-
@click="handleRemoveFromCart(product.key)"
47-
class="absolute md:opacity-0 group-hover:opacity-100 top-2 right-2 md:-top-1 md:-right-1 transition bg-red-700 flex p-1 items-center justify-center rounded-full hover:bg-red-500 active:scale-95">
48-
<UIcon :name="removeFromCartButtonStatus === 'remove' ? 'i-iconamoon-trash-light' : 'i-svg-spinners-90-ring-with-bg'" size="18" class="text-white" />
49-
</button>
35+
<div
36+
class="absolute md:opacity-0 group-hover:opacity-100 top-2 right-2 md:-top-1 md:-right-1 transition space-y-0.5 flex flex-col p-0.5 bg-neutral-800 border border-white/5 items-center justify-center rounded-full">
37+
<div class="bg-white/10 hover:bg-white/30 transition-all rounded-full p-0.5 w-5 h-5 flex items-center justify-center">
38+
<UIcon size="14" name="i-iconamoon-sign-plus" class="text-black dark:text-white cursor-pointer" @click="increment(product.variation.node.databaseId)" />
39+
</div>
40+
<span class="text-center text-sm">{{ product.quantity }}</span>
41+
<div class="bg-white/10 hover:bg-white/30 transition-all rounded-full p-0.5 w-5 h-5 flex items-center justify-center">
42+
<UIcon
43+
size="14"
44+
:name="product.quantity > 1 ? 'i-iconamoon-sign-minus' : 'i-iconamoon-trash-light'"
45+
class="text-black dark:text-white cursor-pointer"
46+
@click="decrement(product.variation.node.databaseId)" />
47+
</div>
48+
</div>
5049
</div>
5150
</div>
5251
</div>

app/composables/useCart.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { push } from 'notivue';
44
export const useCart = () => {
55
const cart = useState<CartItem[]>('cart', () => []);
66
const addToCartButtonStatus = ref<AddBtnStatus>('add');
7-
const removeFromCartButtonStatus = ref<RemoveBtnStatus>('remove');
87

98
const findItem = (variationId: number) => cart.value.find(i => i.variation?.node?.databaseId === variationId);
109

@@ -43,15 +42,6 @@ export const useCart = () => {
4342
updateCart(quantity <= 0 ? cart.value.filter(i => i.key !== key) : cart.value.map(i => (i.key === key ? { ...i, quantity } : i)));
4443
};
4544

46-
const handleRemoveFromCart = (key: string) => {
47-
try {
48-
removeFromCartButtonStatus.value = 'loading';
49-
changeQty(key, 0);
50-
} finally {
51-
removeFromCartButtonStatus.value = 'remove';
52-
}
53-
};
54-
5545
const increment = (variationId: number) => {
5646
const item = findItem(variationId);
5747
if (!item) return handleAddToCart(variationId);
@@ -79,9 +69,7 @@ export const useCart = () => {
7969
return {
8070
cart,
8171
addToCartButtonStatus,
82-
removeFromCartButtonStatus,
8372
handleAddToCart,
84-
handleRemoveFromCart,
8573
increment,
8674
decrement,
8775
};

i18n/locales/en-GB.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"product": {
6565
"originally": "Originally",
6666
"size": "Size",
67-
"quantity": "Qty",
67+
"quantity": "Quantity",
6868
"sku": "article number",
6969
"vat_included": "VAT included",
7070
"featured_information": "Featured Information",

0 commit comments

Comments
 (0)