From 6a14ad0a74d954b6da9aac21839a5c844949ec9c Mon Sep 17 00:00:00 2001 From: Nikita Kiselev Date: Tue, 22 Jul 2025 23:44:01 +0300 Subject: [PATCH] wip: add to cart btn, haptic touch --- spa/src/components/Quantity.vue | 4 ++++ spa/src/views/Cart.vue | 7 ++++++- spa/src/views/Product.vue | 8 ++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spa/src/components/Quantity.vue b/spa/src/components/Quantity.vue index 9dfe78f..7350d89 100644 --- a/spa/src/components/Quantity.vue +++ b/spa/src/components/Quantity.vue @@ -33,6 +33,8 @@ const btnClassList = computed(() => { function inc() { if (props.disabled) return; + window.Telegram.WebApp.HapticFeedback.selectionChanged(); + if (props.max && model.value + 1 > props.max) { model.value = props.max; return; @@ -44,6 +46,8 @@ function inc() { function dec() { if (props.disabled) return; + window.Telegram.WebApp.HapticFeedback.selectionChanged(); + if (model.value - 1 >= 1) { model.value--; } diff --git a/spa/src/views/Cart.vue b/spa/src/views/Cart.vue index 417c4b1..5824698 100644 --- a/spa/src/views/Cart.vue +++ b/spa/src/views/Cart.vue @@ -42,7 +42,7 @@ v-model="item.quantity" @update:modelValue="cart.setQuantity(item.cart_id, $event)" /> - @@ -81,6 +82,9 @@ const cart = useCartStore(); const quantity = ref(1); const error = ref(''); +const isInCart = ref(false); +const btnText = computed(() => isInCart.value ? 'В корзине' : 'Купить'); + const canAddToCart = computed(() => { if (!product.value || product.value.options === undefined || product.value.options?.length === 0) { return true; @@ -98,8 +102,8 @@ const canAddToCart = computed(() => { async function actionBtnClick() { try { error.value = ''; - console.log(product.value); await cart.addProduct(productId.value, product.value.name, product.value.price, quantity.value, product.value.options); + isInCart.value = true; window.Telegram.WebApp.HapticFeedback.notificationOccurred('success'); } catch (e) { await window.Telegram.WebApp.HapticFeedback.notificationOccurred('error');