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

Jk bm estimated next date #30

Merged
merged 5 commits into from
Mar 7, 2024
Merged

Jk bm estimated next date #30

merged 5 commits into from
Mar 7, 2024

Conversation

borjaMarti
Copy link
Collaborator

Description

For this feature we installed the @the-collab-lab/shopping-list-utils dependency so we could import the calculateEstimate function, which we use to generate a new dateNextPurchased each time an item is marked as purchased.

Related Issue

Closes #11

Acceptance Criteria

  • When the user purchases an item, the item’s dateNextPurchased property is calculated using the calculateEstimate function and saved to the Firestore database
    • dateNextPurchased is saved as a date, not a number
  • A getDaysBetweenDates function is exported from utils/dates.js and imported into api/firebase.js
    • This function takes two JavaScript Dates and return the number of days that have passed between them

Type of Changes

Type
✨ New database feature
🔗 Update dependencies

Updates

Before

image

After

image

Testing Steps / QA Criteria

  • Run git pull origin jk-bm-estimated-next-date to pull commit.
  • Run npm install to update dependencies.
  • Create an item.
  • Check Firestore's document dateNextPurchased.
  • Mark item as purchased.
  • Check Firestore's document for updated dateNextPurchased.

Copy link

github-actions bot commented Mar 6, 2024

Visit the preview URL for this PR (updated for commit d5505f7):

https://tcl-71-smart-shopping-list--pr30-jk-bm-estimated-next-f2fkai6w.web.app

(expires Thu, 14 Mar 2024 10:53:14 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 1e7ade9d0f374c4ddb5d7ab6fc541062fc7a1ab4

);
const prevEstimate = dateLastPurchased
? getDaysBetweenDates(dateNextPurchased, dateLastPurchased)
: undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for your work!
I have a question regarding lines 200-202: In place of undefined, I would have added a calculation getDaysBetweenDates(dateNextPurchased, dateCreated), to get the initial count of days before the first purchase. What is the reason behind setting it to undefined?
@borjaMarti @BikeMouse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey Céline!

You are totally right, we updated the implementation to take into account that period instead of passing undefined as the default.

Thanks for the feedback! 😄

Copy link
Collaborator

@vivitt vivitt left a comment

Choose a reason for hiding this comment

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

Nice job! I think the feature works as expected, and I appreciate that you documented the new function in dates.js.

I'd also like to comment about setting prevEstimate in firebase.js to the value that the user submitted when creating the item as daysUntilNextPurchase:

	const prevEstimate = dateLastPurchased
		? getDaysBetweenDates(dateNextPurchased, dateLastPurchased)
		: getDaysBetweenDates(dateNextPurchased, dateCreated)

Is there a specific reason for keeping it as undefined if dateLastPurchased is null?

🙌🏽 Thanks!

…ut until next purchase preference for the first purchases
@borjaMarti
Copy link
Collaborator Author

Nice job! I think the feature works as expected, and I appreciate that you documented the new function in dates.js.

I'd also like to comment about setting prevEstimate in firebase.js to the value that the user submitted when creating the item as daysUntilNextPurchase:

	const prevEstimate = dateLastPurchased
		? getDaysBetweenDates(dateNextPurchased, dateLastPurchased)
		: getDaysBetweenDates(dateNextPurchased, dateCreated)

Is there a specific reason for keeping it as undefined if dateLastPurchased is null?

🙌🏽 Thanks!

Hey Viviana!

I adressed this on the reply to Céline as well.

Thanks for the feedback! ^^

Copy link
Collaborator

@ocsiddisco ocsiddisco left a comment

Choose a reason for hiding this comment

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

It works nicely! Thank you!

@BikeMouse BikeMouse requested a review from llyorshch March 7, 2024 11:15
Copy link
Collaborator

@llyorshch llyorshch left a comment

Choose a reason for hiding this comment

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

Good work! 👏

@borjaMarti borjaMarti merged commit bdd0ac7 into main Mar 7, 2024
2 checks passed
@borjaMarti borjaMarti deleted the jk-bm-estimated-next-date branch April 2, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants