Closed patty-rose closed 1 year ago
Visit the preview URL for this PR (updated for commit ccc3edd):
https://tcl-65-smart-shopping-list--pr24-is-po-10-compute-ne-2t0nuhs4.web.app
(expires Sun, 24 Sep 2023 15:37:09 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Sign: a91b8fb0f37677e20d8afa3e8ea496251536f9b8
@shannonerhea @lydiadunning OK, we updated the code and edited the PR to account for this edge-case. Plese reach out if you continue to have questions :)
The site preview behaves the way described in the QA steps
One of the ACs isn't met. getDaysBetweenDates: This function takes two JavaScript Dates and returns the number of days that have passed between them.
Currently, getDaysBetweenDates takes one number (representing a Date in seconds) and returns the number of days that have passed between that date and the current date.
Hi Lydia we addressed this issue in our latest Push. Thanks
Description
This PR will utilize the
calculateEstimate
function imported from the-collab-lab's shopping-list-utils, to "smart" calculate purchase frequency estimates based on how often the user purchases the list item.We created getDaysBetweenDates function in dates.js which calculates amount of days between date last purchased and current date. Updated ListItem.jsx checkbox handler to be more concise, using
item
over multiple parameters. In Firebase.js we updated addItem so it would include the estimated days until next purchase as submitted in the add-item form. Lastly, in Firebase.js we updated updateItem() to use thecalculateEstimate
function (imported from the-collab-lab-utils) to calculate the estimated days until next purchase. Finally updating the db with the new estimated next purchase date as well as the new last purchase date.Related Issue
closes #10
Acceptance Criteria
dateNextPurchased
property is calculated using thecalculateEstimate
function and saved to the Firestore databasedateNextPurchased
is saved as a date, not a numbergetDaysBetweenDates
function is exported fromutils/dates.js
and imported intoapi/firebase.js
Type of Changes
Video Demo:
https://github.com/the-collab-lab/tcl-65-smart-shopping-list/assets/101524326/0abb499b-d284-4d0a-ae3f-f4d1eaab9cd5
Notice the dateNextPurchased estimate gets smaller, as the calculateEstimate function takes into account the totalPurchases.
Testing Steps / QA Criteria
-Open the GitHub demo -create a new list or use an old list -add an item, remember what you select for "how soon will you buy this again?" -find that item in the firebase database console and confirm that "estimatedDaysUntilNextPurchase" matches what you input in the form. -as you click on the checkbox for your item, watch the datNextPurchased estimate get smaller as it takes into account the totalPurchases (click alot!) Editing to add from our Slack discussion: click 1 will update dateLastPurchased with the current date and dateNextPurchased with an updated estimated next purchase date.. the estimated date gets “smarter” in that every time you click you are simulating “buying” that item with 0 days between the last time. So it will assume you need to buy it earlier and earlier. So each successive click will impact the dateNextPurchased. Because there is rounding involved though, sometimes you will see this number decrement an entire day and other times it will seem unchanged. Clicking a lot you should see it change a few times.
Things to consider:
-Currently the checkbox handler is updating the database even when clicked while it's already checked off. Perhaps we want to update it so that it doesn't have an effect unless we are actively checking it off, and not when we are un-checking it. -The
calculateEstimate
function, as-is will return a 0 day estimate for days until next purchase for items that havetotalPurchases
< 2 andcurrentDate
==dateCreated
. This behavior felt odd so we accounted for it in our code through a conditional that checks if thetotalPurchases
< 2, and if so then it will return theestimatedDaysUntilNextPurchase
(as input by user in the form) as the estimate and not run calculations based ontotalPurchases
and date differentials. This is definitely something to consider as a group-- do we want to account for this edge-case? And if so, how?