Skip to content

Commit

Permalink
Declaratively update quick order list
Browse files Browse the repository at this point in the history
Remove unnecessary null check
  • Loading branch information
lhoffbeck committed Feb 28, 2024
1 parent b419047 commit 7b50505
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
9 changes: 8 additions & 1 deletion assets/product-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ if (!customElements.get('product-info')) {
const newProduct = html.querySelector('product-info');
this.swapProductUtility.viewTransition(this, newProduct);
this.relatedProducts?.initializeRecommendations(newProduct.dataset.productId);
this.quickOrderList?.refresh();
};
}

Expand Down Expand Up @@ -358,7 +359,13 @@ if (!customElements.get('product-info')) {
get relatedProducts() {
const sectionId = this.dataset.originalSection || this.dataset.section;
const relatedProductsSectionId = SectionId.getIdForSection(SectionId.parseId(sectionId), 'related-products');
return document.querySelector(`product-recommendations[data-section-id="${relatedProductsSectionId}"]`);
return document.querySelector(`product-recommendations[data-section-id^="${relatedProductsSectionId}"]`);
}

get quickOrderList() {
const sectionId = this.dataset.originalSection || this.dataset.section;
const quickOrderListSectionId = SectionId.getIdForSection(SectionId.parseId(sectionId), 'quick_order_list');
return document.querySelector(`quick-order-list[data-id^="${quickOrderListSectionId}"]`);
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion assets/quick-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (!customElements.get('quick-add-modal')) {
}

preventVariantURLSwitching(productElement) {
productElement.querySelector('product-info')?.setAttribute('data-update-url', 'false');
productElement.querySelector('product-info').setAttribute('data-update-url', 'false');
}

removeDOMElements(productElement) {
Expand Down
11 changes: 0 additions & 11 deletions assets/quick-order-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class QuickOrderList extends HTMLElement {
}

cartUpdateUnsubscriber = undefined;
sectionRefreshUnsubscriber = undefined;

onSubmit(event) {
event.preventDefault();
Expand All @@ -94,21 +93,11 @@ class QuickOrderList extends HTMLElement {
this.refresh();
});

this.sectionRefreshUnsubscriber = subscribe(PUB_SUB_EVENTS.sectionRefreshed, (event) => {
const isParentSectionUpdated =
this.sectionId && (event.data?.sectionId ?? '') === `${this.sectionId.split('__')[0]}__main`;

if (isParentSectionUpdated) {
this.refresh();
}
});

this.sectionId = this.dataset.id;
}

disconnectedCallback() {
this.cartUpdateUnsubscriber?.();
this.sectionRefreshUnsubscriber?.();
}

onChange(event) {
Expand Down

0 comments on commit 7b50505

Please sign in to comment.