-
Notifications
You must be signed in to change notification settings - Fork 834
18m Solution #114
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
Open
SuperSimpleDev
wants to merge
1
commit into
18m
Choose a base branch
from
18m-2
base: 18m
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+19
−1
Open
18m Solution #114
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import {getProduct, loadProductsFetch} from '../data/products.js'; | |
import {orders} from '../data/orders.js'; | ||
import dayjs from 'https://unpkg.com/[email protected]/esm/index.js'; | ||
import formatCurrency from './utils/money.js'; | ||
import {addToCart} from '../data/cart.js'; | ||
|
||
async function loadPage() { | ||
await loadProductsFetch(); | ||
|
@@ -61,7 +62,8 @@ async function loadPage() { | |
<div class="product-quantity"> | ||
Quantity: ${productDetails.quantity} | ||
</div> | ||
<button class="buy-again-button button-primary"> | ||
<button class="buy-again-button button-primary js-buy-again" | ||
data-product-id="${product.id}"> | ||
<img class="buy-again-icon" src="images/icons/buy-again.png"> | ||
<span class="buy-again-message">Buy it again</span> | ||
</button> | ||
|
@@ -81,6 +83,22 @@ async function loadPage() { | |
} | ||
|
||
document.querySelector('.js-orders-grid').innerHTML = ordersHTML; | ||
|
||
document.querySelectorAll('.js-buy-again').forEach((button) => { | ||
button.addEventListener('click', () => { | ||
addToCart(button.dataset.productId); | ||
|
||
// (Optional) display a message that the product was added, | ||
// then change it back after a second. | ||
button.innerHTML = 'Added'; | ||
setTimeout(() => { | ||
button.innerHTML = ` | ||
<img class="buy-again-icon" src="images/icons/buy-again.png"> | ||
<span class="buy-again-message">Buy it again</span> | ||
`; | ||
}, 1000); | ||
}); | ||
}); | ||
} | ||
|
||
loadPage(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed that the
estimatedDeliveryTime
response from the POST/orders
does not use isWeekend().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does not. But the "skipping weekends part" was an exercise. Lesson 15 Exercise 15m.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@a10n-jsd use this code
Alternate version of calculateDeliveryDate(). Put this code in deliveryOptions.js
this calculates not from current date but the day we ordered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@im-anuj thanks dude!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please tell where do we have to put the code you gave above alternate version of calculatedeliverydate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can put these code at bottom of deliveryOptions.js file, and then can import in order.js and tracking.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if anyone having problems, you can checkout my repo- https://github.com/im-anuj/shopping-site-vanilla
i have done all the assignments and modified it a bit, hope it helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks i just put it inside order.js and made it a function so i can export it to tracking.