-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sorts list by urgency #30
Conversation
Visit the preview URL for this PR (updated for commit f22e906): https://tcl-55-smart-shopping-list--pr30-yj-jf-sort-list-by-u-jh7vny1a.web.app (expires Sun, 21 May 2023 18:05:00 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 607d14028385ebfcc7c9ec69a7bb14d95ed54078 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Love the use of reduce
in the firebase.js
functions and the code was easy to follow. Everything worked as expected in testing.
src/api/firebase.js
Outdated
@@ -55,6 +54,72 @@ export function getItemData(snapshot) { | |||
.filter((item) => item.name !== null); | |||
} | |||
|
|||
function sortItems(item1, item2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically a "compare" function as no sorting happens, just comparing two values and is passed as the compare function to a sort
src/api/firebase.js
Outdated
} else if (item1.daysUntilPurchase > item2.daysUntilPurchase) { | ||
return 1; | ||
} | ||
if (item1.name < item2.name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we normalize the item name like we do on the add item page? What happens when we sort ['bAby', 'aBBy', 'Baby', 'Abby']
all with the same date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Lyle, I don't think we need to worry about the scenario you bought up. Remember how for issue #9 me and Katherine would prevent duplicate items like that ending up in our list in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yaosaur @jeremiahfallin there seems to be an issue with the alphabetical sorting based on case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mentalcaries good catch, should be fixed now.
…ollab-lab/tcl-55-smart-shopping-list into yj-jf-sort-list-by-urgency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is functioning as it should - from the user end, I like the categorization headers and coloring for the check boxes.
From the code side, complicated but great use of .reduce()
in firebase.js
. Also liked use of <Fragment>
so you could utilize key as a prop in mapping.
Description
This code adds a new function
comparePurchaseUrgency
which takes in a list of items and usesgetDaysBetweenDates
created in #10 to calculatedaysUntilNextPurchase
anddaysSinceLastPurchase
for each item in a list utilizing the item'sdateNextPurchased
anddateLastPurchased
properties, respectively. ThecomparePurchaseUrgency
function also uses various arrays of "urgency" (overdue
,soon
,kindOfSoon
,notSoon
, andinactive
) that these items are put into based on the criteria outlined in #12. After this initial sorting of "urgency" is done, we sort the items in each array by theirdaysUntilPurchase
property ascending, which we added from the first step, and then alphabetically by name. Lastly, we return an object from the function that holds all the sorted "urgency" arrays in the order they will be displayed as listed above.In
List.jsx
, we importedcomparePurchaseUrgency
and set our data to the object returned from the function after we passed in our list of items. Finally, we added corresponding headers above each array before mapping it and changed the color of the checkboxes inListItem.css
so users can differentiate among their items.We also removed a duplicate
useNavigate
variable declaration inList.jsx
.Related Issue
Closes #12
Acceptance Criteria
api/firestore.js
exports a newcomparePurchaseUrgency
function with the following behaviorsConsider what happens when an item’s
dateNextPurchased
has passed, but it isn’t yet inactive. Let’s call that item “overdue”.comparePurchaseUrgency
to sort “overdue” items to the top of the listType of Changes
Updates
Before
After
Testing Steps / QA Criteria
In your terminal, use
git checkout -b yj-jf-sort-list-by-urgency
to create a new branch and switch over.Use
git pull origin yj-jf-sort-list-by-urgency
to bring the changes from remote to local.npm start
to start a local instance of our app.Please join an existing list with items already populated. I recommend using
curry rowdy seth
as the list token as that collection has items in every single urgency category.List
view and you should see different headers each followed by a list of item(s) with the same checkbox color. The sections that you might see and their associated colors are as follows (in this order): Overdue: purple, Soon: red, Kind of soon: orange, Not soon: yellow, and Inactive: gray).my test list
for an example)dateNextPurchased
has passed, but today is not more than 59 days fromdateLastPurchased
dateNextPurchased
is not more than 7 days from todaydateNextPurchased
is between 7- 30 days from todaydateNextPurchased
is 30 or more days from todaydateLastPurchased
dateNextPurchased
and if its the same number of days, then alphabetically by name. Note that for days in the past those are considered negative days and should be displayed first compared to positive days in the future.