Skip to content

Commit 019fc9e

Browse files
authored
Avoid infinite calls in range sliders (#207)
1 parent d737851 commit 019fc9e

3 files changed

Lines changed: 13 additions & 98 deletions

File tree

src/app/shared/cart-card/cart-card.component.ts

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -105,95 +105,6 @@ export class CartCardComponent implements OnInit {
105105
}
106106
}
107107

108-
/*async addProductToCart(productOff:Product| undefined,options:boolean){
109-
//this.localStorage.addCartItem(productOff as Product);
110-
if(options==true){
111-
console.log('termschecked:')
112-
console.log(this.selected_terms)
113-
if(productOff!= undefined && productOff?.productOfferingPrice != undefined){
114-
let prodOptions = {
115-
"id": productOff?.id,
116-
"name": productOff?.name,
117-
"image": this.getProductImage(),
118-
"href": productOff.href,
119-
"options": {
120-
"characteristics": this.selected_chars,
121-
"pricing": this.selected_price
122-
},
123-
"termsAccepted": this.selected_terms
124-
}
125-
this.lastAddedProd=prodOptions;
126-
await this.cartService.addItemShoppingCart(prodOptions).subscribe({
127-
next: data => {
128-
console.log(data)
129-
console.log('Update successful');
130-
},
131-
error: error => {
132-
console.error('There was an error while updating!', error);
133-
if(error.error.error){
134-
console.log(error)
135-
this.errorMessage='Error: '+error.error.error;
136-
} else {
137-
this.errorMessage='There was an error while adding item to the cart!';
138-
}
139-
this.showError=true;
140-
setTimeout(() => {
141-
this.showError = false;
142-
}, 3000);
143-
}
144-
});
145-
}
146-
} else {
147-
if(productOff!= undefined && productOff?.productOfferingPrice != undefined){
148-
let prodOptions = {
149-
"id": productOff?.id,
150-
"name": productOff?.name,
151-
"image": this.getProductImage(),
152-
"href": productOff.href,
153-
"options": {
154-
"characteristics": this.selected_chars,
155-
"pricing": this.selected_price
156-
},
157-
"termsAccepted": true
158-
}
159-
this.lastAddedProd=prodOptions;
160-
await this.cartService.addItemShoppingCart(prodOptions).subscribe({
161-
next: data => {
162-
console.log(data)
163-
console.log('Update successful');
164-
},
165-
error: error => {
166-
console.error('There was an error while updating!', error);
167-
if(error.error.error){
168-
console.log(error)
169-
this.errorMessage='Error: '+error.error.error;
170-
} else {
171-
this.errorMessage='There was an error while adding item to the cart!';
172-
}
173-
this.showError=true;
174-
setTimeout(() => {
175-
this.showError = false;
176-
}, 3000);
177-
}
178-
});
179-
}
180-
}
181-
if(productOff!== undefined){
182-
this.eventMessage.emitAddedCartItem(productOff as cartProduct);
183-
this.eventMessage.emitCloseCartCard(productOff as cartProduct);
184-
this.check_char=false;
185-
this.check_terms=false;
186-
this.check_prices=false;
187-
this.selected_chars=[];
188-
this.selected_price={};
189-
this.selected_terms=false;
190-
this.cdr.detectChanges();
191-
}
192-
193-
this.cdr.detectChanges();
194-
}
195-
*/
196-
197108
async addProductToCart(productOff: Product | undefined, options: boolean) {
198109
if (!productOff || !productOff.productOfferingPrice) return;
199110

@@ -399,7 +310,7 @@ export class CartCardComponent implements OnInit {
399310
return str.split(/\s+/).some(word => word.length > threshold);
400311
} else {
401312
return false
402-
}
313+
}
403314
}
404315

405316
}

src/app/shared/characteristic/characteristic.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ <h4 class="text-lg font-semibold text-primary-100 dark:text-gray-300">{{ charact
1616
[min]="getSliderRange()?.min"
1717
[max]="getSliderRange()?.max"
1818
[formControl]="control"
19+
(change)="onControlCommit()"
1920
class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
2021
/>
2122
<span class="min-w-24 flex justify-center text-sm text-gray-600 dark:text-gray-400">{{ control.value }} {{ getUnit() }}</span>
@@ -24,6 +25,7 @@ <h4 class="text-lg font-semibold text-primary-100 dark:text-gray-300">{{ charact
2425
<div>
2526
<select
2627
[formControl]="control"
28+
(change)="onControlCommit()"
2729
class="block w-full px-3 py-2 border border-gray-300 rounded-lg text-sm shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-300 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600"
2830
>
2931
<option

src/app/shared/characteristic/characteristic.component.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ export class CharacteristicComponent implements OnInit {
5656
);
5757
}
5858

59-
// Emit initial value
60-
this.control.valueChanges.subscribe((value) => {
61-
if (!this.readOnly) { // Respetar el estado de solo lectura
62-
this.valueChange.emit({
63-
characteristicId: this.characteristic.id,
64-
selectedValue: value,
65-
});
66-
}
59+
}
60+
61+
onControlCommit(): void {
62+
if (this.readOnly) {
63+
return;
64+
}
65+
66+
this.valueChange.emit({
67+
characteristicId: this.characteristic.id,
68+
selectedValue: this.control.value,
6769
});
6870
}
6971

0 commit comments

Comments
 (0)