the-collab-lab / tcl-23-smart-shopping-list

1 stars 2 forks source link

Issue #8 - Mark an item on my shopping list as purchased #22

Closed apdsrocha closed 3 years ago

apdsrocha commented 3 years ago

Description

This PR updates the List view which was previously displaying the information straight from the JSON file. The list items are now showing individual list items with a checkbox that can be used to mark purchased items.

Related Issue

closes #9

Acceptance Criteria

Type of Changes

Type
:bug: Bug fix
✓ :sparkles: New feature
:hammer: Refactoring
:100: Add tests
:link: Update dependencies
:scroll: Docs

Updates

Before

Screen Shot 2021-04-26 at 7 35 34 PM

https://user-images.githubusercontent.com/47455758/116334400-c2cdc700-a79a-11eb-8571-0fd94d637b0f.mp4

After

Screen Shot 2021-04-26 at 7 36 30 PM

https://user-images.githubusercontent.com/47455758/116334417-ca8d6b80-a79a-11eb-8208-274f98e64c55.mp4

Testing Steps / QA Criteria

  1. run git checkout jc-ar-mark-items-purchased
  2. run npm install
  3. run npm start
  4. If you need to enter a token, you can use sire agnew dutch
  5. If a checkbox is checked blue already, that means it was marked purchased less than 24 hours prior. Check any boxes that are unchecked, and uncheck any boxes that are checked. Hit refresh and they will each maintain their checked or unchecked stats.
  6. If you add a new item, you will see that the checkbox is initially unchecked.

Notes

function compareTimeStamps(lastPurchased) {
  const currentElapsedMilliseconds = Date.now();
  const millisecondsInOneDay = 86400000;
  return currentElapsedMilliseconds - lastPurchased < millisecondsInOneDay;
}
...
<ul>
  {listItem.docs.map((doc) => (
    <div className="checkbox-wrapper">
      <input
        type="checkbox"
        defaultChecked={
          compareTimeStamps(doc.data().last_purchased) ? true : false
         }
         onClick={(e) => markItemPurchased(e, doc.id)}
       />
      <li key={doc.id}>{doc.data().item_name}</li>
    </div>
  ))}
</ul>

Updates

That said, I removed lines 16-19:

} else {
  db.collection(props.token).doc(id).update({
    last_purchased: null,
  });
github-actions[bot] commented 3 years ago

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

https://tcl-23-shopping-list--pr22-jc-ar-mark-items-pur-jmjj22gz.web.app

(expires Sun, 09 May 2021 17:19:22 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

jamesncox commented 3 years ago

Ready for merge approval!