wip: add to cart btn, haptic touch
This commit is contained in:
@@ -47,10 +47,11 @@
|
||||
<div class="flex-1">
|
||||
<button
|
||||
class="btn btn-primary btn-lg w-full"
|
||||
:class="isInCart ? 'btn-success' : 'btn-primary'"
|
||||
:disabled="canAddToCart === false"
|
||||
@click="actionBtnClick"
|
||||
>
|
||||
Купить
|
||||
{{ btnText }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user