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

Mm qg predict next purchase #27

Merged
merged 4 commits into from
Sep 15, 2024
Merged

Mm qg predict next purchase #27

merged 4 commits into from
Sep 15, 2024

Conversation

marshjaja
Copy link
Collaborator

Description

When a new purchase is recorded the next purchase date is automatically computed and the app learn how often the item is 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

enhancement

Updates

Before

N/A

After

N/A

Testing Steps / QA Criteria

  • Do a git pull and git checkout mm-qg-predict-next-purchase.
  • Open the homepage by running npm start.
  • Navigate to the List and check one of the items on the list.
  • Check Firestore: the dateLastPurchased, dateNextPurchased and dayInterval should be updated according to how many days have elapsed since the item was last purchased.

Copy link

github-actions bot commented Sep 11, 2024

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

https://tcl-79-smart-shopping-list--pr27-mm-qg-predict-next-p-eticpkkj.web.app

(expires Sun, 22 Sep 2024 12:45:53 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: d91d9ddbda780208241c52942f544acf8e81407a

Copy link
Collaborator

@joriordan332 joriordan332 left a comment

Choose a reason for hiding this comment

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

Looks great guys! Well done

Copy link
Collaborator

@Hudamabkhoot Hudamabkhoot left a comment

Choose a reason for hiding this comment

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

Amazing work well done!

Copy link
Collaborator

@redapy redapy left a comment

Choose a reason for hiding this comment

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

Amazing work handling this issue, well done!!! I left a couple of adjustments that should be tackled before we can merge this PR.

Also, I noticed that you're fetching the item data inside the updateItem function, which isn't necessary. Since we already have the latest data from the useShoppingListData custom hook, it would be more efficient to pass that data down to the Item component and then into the updateItem function. This way, we avoid redundant fetches, making fewer API calls, which is always better for performance.


if (checked) {
await updateDoc(itemRef, {
dateLastPurchased: new Date(),
dateLastPurchased: Timestamp.fromDate(new Date()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe it's enough to just have new Date() or the today variable you defined

Comment on lines 224 to 226
dateNextPurchased: Timestamp.fromMillis(
today.setDate(today.getDate() + estimate),
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use the helper function getFutureDate that you already have to convert the estimate to a javascript date

Comment on lines 204 to 206
const dateLastPurchasedJavaScriptObject = data.dateLastPurchased
? data.dateLastPurchased.toDate()
: today;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the item has never been purchased, we should use the date it was created at instead of today

@@ -13,7 +13,7 @@ export function ListItem({ name, listPath, id, isChecked, datePurchased }) {

useEffect(() => {
const today = new Date().getTime();
const datePurchasedInMillis = datePurchased?.toMillis();
const datePurchasedInMillis = datePurchased;
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like the ?.toMillis that got deleted here is causing the items to uncheck whenever the page refreshes, which is not the desired behavior

@marshjaja marshjaja merged commit 8704b58 into main Sep 15, 2024
2 checks passed
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