handleQuantityButton(button) { const container = button.parentElement; const input = container?.querySelector('input[data-qty-input]'); const display = container?.querySelector('[data-qty-render]');
if (!input) return;
const currentQty = parseInt(input.value) || 0; const isPlus = button.dataset.qty === 'plus'; const newQty = isPlus ? currentQty + 1 : Math.max(0, currentQty - 1);
// IMMEDIATE visual update (no wait) input.value = newQty; if (display) display.textContent = newQty;
const lineIndex = input.dataset.index || input.dataset.qtyIndex; if (lineIndex) { // Use debounced version for API call this.debouncedUpdateQuantity(lineIndex, newQty, input.getAttribute('name')); } }
// Add in constructor: constructor() { super(); // ... existing code ...
// Separate debounced method for quantity updates this.debouncedUpdateQuantity = debounce( (line, qty, name) => this.updateQuantity(line, qty, name), 300 ); }