generated from the-collab-lab/smart-shopping-list-deprecated
-
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
Np mj sort items soon integers #66
Draft
MonicaDJohnson
wants to merge
13
commits into
master
Choose a base branch
from
np-mj-sort-items-soon-integers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3485388
make PR
ajiles91 2e2ac6e
added estimates.js
ajiles91 ff7293e
added comment to additem.js to test branch pull
MonicaDJohnson 350f846
Merge branch 'aj-mj-add-number-of-purchases' of https://github.com/th…
MonicaDJohnson 74fcb83
working on counter
MonicaDJohnson 2a03d00
counter set up for numberOfPurchases variable
ajiles91 ae3f81f
Merge pull request #65 from the-collab-lab/aj-mj-add-number-of-purchases
ajiles91 f7a7099
implemented adding calculated estimate to items in database with fake…
ajiles91 3969747
added prevDate variable to try to calculate time interval for calcula…
ajiles91 1bf2df9
Merge branch 'master' into np-mj-sort-items-soon-integers
e9a3eea
Fix remaining holdovers from branching
2e2f328
attempt to filter to <= 7
mikeramz86 7e53584
trying to sort by nextExpectedPurchased
ajiles91 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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import dayjs from 'dayjs'; | ||
import React, { useContext, useState } from 'react'; | ||
import { FirestoreCollection } from 'react-firestore'; | ||
|
||
import { ListContext } from '../listContext'; | ||
import useListToken, { getCurrentToken } from '../useListToken'; | ||
import NavTabs from '../components/NavTabs'; | ||
import Loading from '../components/Loading'; | ||
import normalizeName from '../lib/normalizeName'; | ||
|
||
function isLessThan24hrs(datePurchased) { | ||
return dayjs().diff(dayjs(datePurchased), 'hours') <= 24; | ||
} | ||
|
||
//we are checking if the last date it was purchased is less than 24hrs using isLessThan24hrs function | ||
function isChecked(lastDatePurchased) { | ||
return !!lastDatePurchased && isLessThan24hrs(lastDatePurchased); | ||
} | ||
|
||
const ListSort = props => { | ||
const now = new Date(); | ||
// const today = dayjs(now); | ||
|
||
const [filteredInput, setFilteredInput] = useState(''); | ||
const { shoppingList, setShoppingList, purchaseItem } = useContext( | ||
ListContext, | ||
); | ||
const { token } = useListToken(); | ||
|
||
function handlePurchasedChange(item) { | ||
// We don't want to uncheck ourselves. We should have a separate ticket for handling a mis-check | ||
// What would we set datePurchased to on an uncheck? Can't be null if we've purchased or our suggestions | ||
// are goofed. Maybe we live with that, or we could keep the most recent lastDatePurchased in case | ||
// of a mistake. For this ticket, let's keep it simple. | ||
if (!isChecked(item.lastDatePurchased)) { | ||
purchaseItem(item, Date.now()); | ||
} | ||
} | ||
|
||
function handleFilterChange(event) { | ||
setFilteredInput(event.target.value); | ||
} | ||
|
||
//5. way to clear out the filter | ||
|
||
function filterListInput(name) { | ||
return normalizeName(name).includes(normalizeName(filteredInput)); | ||
} | ||
|
||
return ( | ||
<> | ||
<FirestoreCollection | ||
// Specify the path to the collection you're pulling data from | ||
path="items" | ||
// Sort the data | ||
sort="nextExpectedPurchase:asc" | ||
// Only fetch the items associated with the token saved in localStorage | ||
filter={[ | ||
'token', | ||
'==', | ||
token || getCurrentToken() || 'no token set', | ||
'nextExpectedPurchase', | ||
'<=', | ||
7, | ||
]} | ||
// isLoading = is a Boolean that represents the loading status for the firebase query. true until an initial payload from Firestore is received. | ||
// data = an Array containing all of the documents in the collection. Each item will contain an id along with the other data contained in the document. | ||
render={({ isLoading, data }) => { | ||
if (!isLoading) { | ||
setShoppingList(data); | ||
} | ||
return isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
<div className="listFilter"> | ||
<input | ||
type="search" | ||
onChange={handleFilterChange} | ||
value={filteredInput} | ||
></input> | ||
<button onClick={() => setFilteredInput('')}>X</button> | ||
</div> | ||
<ul className="shopping-list"> | ||
{shoppingList | ||
.filter(item => filterListInput(item.name)) | ||
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. @stevelikesmusic can we add the comparison here? |
||
.map((item, index) => ( | ||
<li key={index}> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={isChecked(item.lastDatePurchased)} | ||
onChange={() => handlePurchasedChange(item)} | ||
disabled={ | ||
isChecked(item.lastDatePurchased) | ||
? 'disabled' | ||
: false | ||
} | ||
/> | ||
{item.name} | ||
</label> | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
}} | ||
/> | ||
<NavTabs /> | ||
</> | ||
); | ||
}; | ||
export default ListSort; |
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.
@stevelikesmusic I think this is wrong but what I was trying to attempt is to compare
nextExpectedPurchase
with an integer and if that integer is <= 7 then I want only those items shown.