Closed isaabutaa closed 3 years ago
Visit the preview URL for this PR (updated for commit a9430c4):
https://tcl-28-shopping-list--pr33-experimenting-with-e-80rnrgs9.web.app
(expires Thu, 19 Aug 2021 12:50:13 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Yes @sandaiiyahh I think that's a great idea! 💯 I'll see if I can implement that condition
@sandaiiyahh I put a ternary statement in the .update()
for the daysUntilPurchase
value checking to see if the checkbox is checked like you suggested. 👇
daysUntilPurchase: e.target.checked ? nextPurchaseDate : daysUntilPurchase
My code editor did an auto format, so the ternary is on multiple lines. But it works! daysUntilPurchase
gets updated now only if the box is being checked, not unchecked.
@sandaiiyahh I put a ternary statement in the
.update()
for thedaysUntilPurchase
value checking to see if the checkbox is checked like you suggested. 👇
daysUntilPurchase: e.target.checked ? nextPurchaseDate : daysUntilPurchase
My code editor did an auto format, so the ternary is on multiple lines. But it works!
daysUntilPurchase
gets updated now only if the box is being checked, not unchecked.
Hmm, I think it will still calculate the estimate under the hood whenever it's checked or unchecked. But yes, that works too!
Hmm, I think it will still calculate the estimate under the hood whenever it's checked or unchecked. But yes, that works too!
That's a really good point! I hadn't considered that.
Hmm, I think it will still calculate the estimate under the hood whenever it's checked or unchecked. But yes, that works too!
@sandaiiyahh I updated the code so that calculateEstimate
is inside a condition statement. Should be good now. 😎
let nextPurchaseDate;
if (e.target.checked) {
nextPurchaseDate = calculateEstimate(
daysUntilPurchase,
latestInterval,
numberOfPurchases + 1,
);
}
Description
Made a couple small changes based on @ksiman14's comments on sd-ia-estimate-next-purchase PR.
numberOfPurchases
should only increment if item was previously not purchased and the user checks the box. Should not increment if box is uncheckedfrequency
variable intoSingleItem
component through propslatestInterval
value as set tofrequency
NOTE: I did notice that since we are using the
calculateEstimate
function inside ahandleChange
, the estimated next purchase is calculate both when the box is checked and unchecked. So we may need to do something small to refactor.If things changes are okay and we all agree, maybe we can merge this with the sd-ia-estimate-next-estimate branch before merging that branch to main.