Skip to content

Commit

Permalink
simplified checked input checked attribute and moved logic into subtr…
Browse files Browse the repository at this point in the history
…actDates function
  • Loading branch information
hun-ah committed Feb 27, 2024
1 parent 9630a19 commit b5c18cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/components/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export function ListItem({ name, listPath, id, dateLastPurchased }) {
type="checkbox"
name={name}
onChange={handleChecked}
checked={
dateLastPurchased && subtractDates(todaysDate, dateLastPurchased)
? true
: false
}
checked={subtractDates(todaysDate, dateLastPurchased)}
></input>
</label>
</li>
Expand Down
7 changes: 5 additions & 2 deletions src/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function convertTimestamp(timestamp) {
}

export function subtractDates(todaysDate, dateLastPurchased) {
const dateForCompare = convertTimestamp(dateLastPurchased);
if (dateLastPurchased) {
const dateForCompare = convertTimestamp(dateLastPurchased);

return todaysDate.getTime() - dateForCompare < ONE_DAY_IN_MILLISECONDS;
return todaysDate.getTime() - dateForCompare < ONE_DAY_IN_MILLISECONDS;
}
return false;
}

0 comments on commit b5c18cb

Please sign in to comment.