fix: Add null checks before attaching/detaching scroll event listeners and refactor product list display count reset logic.
This commit is contained in:
parent
04af9538f2
commit
0fa1972fe0
@ -33,7 +33,10 @@ patch(OrderWidget.prototype, {
|
||||
});
|
||||
|
||||
onWillUnmount(() => {
|
||||
this.scrollableRef.el?.removeEventListener("scroll", this.onScroll);
|
||||
const el = this.scrollableRef.el;
|
||||
if (el) {
|
||||
el.removeEventListener("scroll", this.onScroll);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -24,35 +24,36 @@ patch(ProductsWidget.prototype, {
|
||||
}
|
||||
}
|
||||
};
|
||||
this.scrollContainer?.addEventListener("scroll", this.onScroll);
|
||||
if (this.scrollContainer) {
|
||||
this.scrollContainer.addEventListener("scroll", this.onScroll);
|
||||
}
|
||||
});
|
||||
|
||||
onWillUnmount(() => {
|
||||
this.scrollContainer?.removeEventListener("scroll", this.onScroll);
|
||||
if (this.scrollContainer) {
|
||||
this.scrollContainer.removeEventListener("scroll", this.onScroll);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
get selectedCategoryId() {
|
||||
if (this._lastCategoryId !== this.pos.selectedCategoryId) {
|
||||
this._lastCategoryId = this.pos.selectedCategoryId;
|
||||
this.state.displayedCount = 40;
|
||||
}
|
||||
return super.selectedCategoryId;
|
||||
},
|
||||
|
||||
get searchWord() {
|
||||
const word = this.pos.searchProductWord.trim();
|
||||
if (this._lastSearchWord !== word) {
|
||||
this._lastSearchWord = word;
|
||||
this.state.displayedCount = 40;
|
||||
}
|
||||
return super.searchWord;
|
||||
},
|
||||
|
||||
get productsToDisplay() {
|
||||
const list = super.productsToDisplay;
|
||||
// The core productsToDisplay returns the full list.
|
||||
// We slice it here for rendering.
|
||||
|
||||
// React to category or search word changes to reset the count
|
||||
const currentCategory = this.selectedCategoryId;
|
||||
if (this._lastCategoryId !== currentCategory) {
|
||||
this._lastCategoryId = currentCategory;
|
||||
this.state.displayedCount = 40;
|
||||
}
|
||||
|
||||
const currentSearch = this.searchWord;
|
||||
if (this._lastSearchWord !== currentSearch) {
|
||||
this._lastSearchWord = currentSearch;
|
||||
this.state.displayedCount = 40;
|
||||
}
|
||||
|
||||
return list.slice(0, this.state.displayedCount);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user