Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] QOL Cart race conditions #3395

Merged
merged 36 commits into from
May 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5bb438c
Cart racing prototype
sofiamatulis Apr 4, 2024
c1037b7
Add promise
sofiamatulis Apr 4, 2024
1a8c8ce
new approach
sofiamatulis Apr 4, 2024
6c6c785
Refactor
sofiamatulis Apr 5, 2024
64a2788
Fix multiple items
sofiamatulis Apr 5, 2024
7f2aee0
Merge branch 'main' into cart-racing
sofiamatulis Apr 5, 2024
d6170be
Merge branch 'main' into cart-racing
sofiamatulis Apr 25, 2024
3b0bc2b
Fix closing tag
sofiamatulis Apr 25, 2024
29ae036
Clean up
sofiamatulis Apr 25, 2024
b900e52
Remove unused var
sofiamatulis Apr 25, 2024
e5f185b
Remove name
sofiamatulis Apr 25, 2024
b76ead6
Clean up ids
sofiamatulis Apr 25, 2024
4e6fb73
Clean up func
sofiamatulis Apr 25, 2024
d208999
Clean up function
sofiamatulis Apr 25, 2024
2f164c5
Check if remove all exists
sofiamatulis Apr 25, 2024
9fc8728
Check if remove all exists
sofiamatulis Apr 25, 2024
e64ce07
Ensure it only updates when the user is done
sofiamatulis Apr 25, 2024
a835730
Remove unused promise
sofiamatulis Apr 26, 2024
0954f4f
Update debouncer
sofiamatulis Apr 29, 2024
1956e70
Fix typo
sofiamatulis Apr 30, 2024
6471174
Create extendable comp
sofiamatulis Apr 30, 2024
7e9500b
import js file
sofiamatulis May 1, 2024
b90f7a5
Feedback
sofiamatulis May 1, 2024
8c119b1
feedback
sofiamatulis May 2, 2024
9b482c8
Update settings json
sofiamatulis May 2, 2024
16e1319
Revert
sofiamatulis May 2, 2024
2623ff8
Fix trash behavior
sofiamatulis May 2, 2024
1177dc1
Revert settings
sofiamatulis May 3, 2024
1d99424
naming
sofiamatulis May 3, 2024
88fe218
Ensure remove buton updates
sofiamatulis May 3, 2024
b51ef46
Fix spacing
sofiamatulis May 3, 2024
4f353f7
Cleanup
sofiamatulis May 3, 2024
e8e7f86
Fix duplication
sofiamatulis May 3, 2024
d7b966c
Fix trash icon behavior;
sofiamatulis May 3, 2024
0683db8
Fix logic
sofiamatulis May 4, 2024
e349ace
Fix loader
sofiamatulis May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cart racing prototype
  • Loading branch information
sofiamatulis committed Apr 4, 2024
commit 5bb438c4f158f2845d7a22112b19d10a0a3d66f3
39 changes: 32 additions & 7 deletions assets/quick-order-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if (!customElements.get('quick-order-list')) {
this.quickOrderListId = `quick-order-list-${this.dataset.productId}`
this.defineInputsAndQuickOrderTable();

this.queue = []
this.variantItemStatusElement = document.getElementById('shopping-cart-variant-item-status');
const form = this.querySelector('form');
this.inputFieldHeight = this.querySelector('.variant-item__quantity-wrapper').offsetHeight;
Expand Down Expand Up @@ -148,7 +149,8 @@ if (!customElements.get('quick-order-list')) {
const quantity = inputValue - cartQuantity;
this.cleanErrorMessageOnType(event);
if (inputValue == 0) {
this.updateQuantity(index, inputValue, name, this.actions.update);
this.queue.push({id: index, quantity: inputValue, name, action: this.actions.update})
this.sendRequest();
} else {
this.validateQuantity(event, name, index, inputValue, cartQuantity, quantity);
}
Expand All @@ -172,9 +174,11 @@ if (!customElements.get('quick-order-list')) {
event.target.setCustomValidity('');
event.target.reportValidity();
if (cartQuantity > 0) {
this.updateQuantity(index, inputValue, name, this.actions.update);
this.queue.push({id: index, quantity: inputValue, name, action: this.actions.update})
this.sendRequest();
} else {
this.updateQuantity(index, quantity, name, this.actions.add);
this.queue.push({id: index, quantity, name, action:this.actions.add})
this.sendRequest();
}
}
}
Expand Down Expand Up @@ -287,6 +291,26 @@ if (!customElements.get('quick-order-list')) {
}
}

sendRequest() {
return new Promise((resolve) => {
if (this.queue.length > 0 || !this.queueRunning) {
this.queue.forEach((q, i) => {
const int = setTimeout(() => {
this.queue = this.queue.filter(item => item !== q)
if (this.queue.length === 0) {
this.queueRunning = false
clearTimeout(int);
}
// Create list of updates here
this.updateQuantity(q.id, q.quantity, q.name, q.action)
resolve()
this.queueRunning = true
}, 500 * (i + 1))
})
}
})
}

getTableHead() {
return document.querySelector('.quick-order-list__table thead');
}
Expand Down Expand Up @@ -400,8 +424,9 @@ if (!customElements.get('quick-order-list')) {
}

updateQuantity(id, quantity, name, action) {
console.log(id, quantity, action, '---')
this.toggleLoading(id, true);
this.cleanErrors();
// this.cleanErrors(id);

let routeUrl = routes.cart_change_url;
let body = JSON.stringify({
Expand Down Expand Up @@ -541,9 +566,9 @@ if (!customElements.get('quick-order-list')) {
this.updateLiveRegions(id, message);
}

cleanErrors() {
this.querySelectorAll('.desktop-row-error').forEach((error) => error.classList.add('hidden'));
this.querySelectorAll(`.variant-item__error-text`).forEach((error) => error.innerHTML = '');
cleanErrors(id) {
// this.querySelectorAll('.desktop-row-error').forEach((error) => error.classList.add('hidden'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is commented out for now given that there is clamping happening + no errors returned from the BE. More info here: https://github.com/Shopify/shopify/issues/440605

// this.querySelectorAll(`.variant-item__error-text`).forEach((error) => error.innerHTML = '');
}

updateLiveRegions(id, message) {
Expand Down
Loading