generated from the-collab-lab/smart-shopping-list
-
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
Sm ar items in order issue 13 #30
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a972d9
implemented getDaysBetweenDate to get days until next purchase
sar-mko f68f23c
filtered list by daysLastPurchased and saved into arrays
sar-mko 0ed0a0d
created a sorted list before filtering
sar-mko b36e20d
sorted list alphabetically if same dateBetween
sar-mko 4cc0191
list renders in order of how soon dateNextPurchase is -- not separate…
arandel1 ff64cbc
beginning of incorporating mindy suggestions
arandel1 0c814b6
rendering sortedList with object.enteries and mapping through
sar-mko 9dff0c9
incorporated filtered list and changed its dependency to sortedlist
sar-mko 7d314d1
added overdue section in firebase
sar-mko 0d550c9
added urgency labels as placeholders
sar-mko 547cad0
replaced x variable name with item to make it more descriptive
arandel1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { ListItem } from '../components'; | ||
import { useState, useEffect } from 'react'; | ||
import BasicModal from './Modal'; | ||
import { comparePurchaseUrgency } from '../api'; | ||
|
||
export function List({ data, userId }) { | ||
const [filterVal, setFilterVal] = useState(''); | ||
const [filteredList, setFilteredList] = useState([]); | ||
const [filteredObject, setFilteredObject] = useState({}); | ||
const [sortedList, setSortedList] = useState([]); | ||
const [showModal, setShowModal] = useState(false); | ||
|
||
const dataEmpty = userId && !data.length; | ||
|
@@ -28,12 +30,26 @@ export function List({ data, userId }) { | |
}; | ||
|
||
useEffect(() => { | ||
setFilteredList( | ||
data.filter((item) => | ||
setSortedList(comparePurchaseUrgency(data)); | ||
}, [data]); | ||
|
||
const labels = { | ||
overdue: 'Overdue (!!!!)', | ||
soon: 'Soon (!!!)', | ||
kindOfSoon: 'Kind of soon (!!)', | ||
notSoon: 'Not soon (!)', | ||
inactive: 'Inactive Items', | ||
}; | ||
|
||
useEffect(() => { | ||
const filteredObject = {}; | ||
Object.entries(sortedList).forEach(([timeBucket, list]) => { | ||
filteredObject[timeBucket] = list.filter((item) => | ||
item.name.toLowerCase().includes(filterVal.toLowerCase()), | ||
), | ||
); | ||
}, [filterVal, data]); | ||
); | ||
}); | ||
setFilteredObject(filteredObject); | ||
}, [filterVal, sortedList]); | ||
|
||
return ( | ||
<> | ||
|
@@ -45,7 +61,7 @@ export function List({ data, userId }) { | |
)} | ||
|
||
<form onSubmit={clearInput}> | ||
<label htmlFor="item-name"> Item name:</label> | ||
<label htmlFor="item-name">Item name:</label> | ||
<input | ||
id="item-name" | ||
name="item-name" | ||
|
@@ -57,10 +73,17 @@ export function List({ data, userId }) { | |
</form> | ||
|
||
<ul> | ||
{filteredList && | ||
filteredList.map((item) => { | ||
return <ListItem key={item.id} item={item} />; | ||
})} | ||
{filteredObject && | ||
Object.entries(filteredObject).map(([timeBucket, list]) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the implementation of using Object.entries here. I definitely learned a bit about data type conversion by looking at this. |
||
<> | ||
<div> | ||
<h3>{labels[timeBucket]}</h3> | ||
</div> | ||
{list.map((item) => ( | ||
<ListItem key={item.id} item={item} /> | ||
))} | ||
</> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like how
getDaysBetwenDates
gets used again here!