-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from the-collab-lab/jvb-dk-sort-by-timeframe
[Feature, Refactor]Order shopping list items by time frame + Code Organization
- Loading branch information
Showing
6 changed files
with
140 additions
and
41 deletions.
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,75 @@ | ||
import React from 'react'; | ||
import * as timeframeConstants from '../lib/timeframeConstants'; | ||
|
||
const timeFrameString = number => | ||
{ | ||
switch(number){ | ||
case 7: | ||
return "Fewer than 7 days"; | ||
case 14: | ||
return "7 to 30 days"; | ||
case 30: | ||
return "More than 30 days"; | ||
case 0: | ||
return "Inactive item"; | ||
default: | ||
return "None"; | ||
} | ||
} | ||
const generateClass = number => | ||
{ | ||
switch(number){ | ||
case 7: | ||
return "soon"; | ||
case 14: | ||
return "kindasoon"; | ||
case 30: | ||
return "notsoon"; | ||
case 0: | ||
return "inactive"; | ||
default: | ||
return "None"; | ||
} | ||
} | ||
// const getStringValue = (numberValue) => { | ||
// const dictionary = {}; | ||
// dictionary[timeframeConstants.SOON.numberValue] = SOON.stringValue; | ||
|
||
// if (dictionary.keys.includes(numberValue)){ | ||
// return dictionary[numberValue]; | ||
// } | ||
// return "error" | ||
// } | ||
|
||
const ShoppingListItem = ({item, handleCheck, setCurrentItem, setModal}) => { | ||
const ariaString = `${item.itemName} to be bought in ${timeFrameString(item.timeFrame)}`; | ||
return ( | ||
<tr className={generateClass(item.timeFrame)}> | ||
<td> | ||
<input | ||
aria-label= {ariaString} | ||
key={item.id} | ||
id={item.id} | ||
type="checkbox" | ||
name={item.id} | ||
value={item.isChecked} | ||
checked={item.isChecked} | ||
onChange={e => handleCheck(e, item)} | ||
/> | ||
</td> | ||
<td>{item.itemName}</td> | ||
<td>{timeFrameString(item.timeFrame)}</td> | ||
<td><button | ||
className="deleteItemButton" | ||
onClick={() => { | ||
setCurrentItem(item); | ||
setModal(true); | ||
}} | ||
> | ||
🗑 | ||
</button></td> | ||
</tr> | ||
); | ||
} | ||
|
||
export default ShoppingListItem; |
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,12 @@ | ||
.soon { | ||
background-color: red; | ||
} | ||
.kindasoon { | ||
background-color: orange; | ||
} | ||
.notsoon { | ||
background-color: green; | ||
} | ||
.inactive { | ||
background-color: grey; | ||
} |
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,9 @@ | ||
const normalizeString = (inputString) => { | ||
const output = inputString | ||
.toLowerCase() | ||
.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, '') | ||
.trim() | ||
.replace(/\s{2,}/g, ' '); | ||
return output | ||
} | ||
export default normalizeString; |
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,6 @@ | ||
const SOON = {stringValue: "fewer that 7 days", integerValue: 7} | ||
const KIND_OF_SOON = {stringValue: "between 7 and 30 days", integerValue: 14} | ||
const NOT_SOON = {stringValue: "more than 30 days", integerValue: 30} | ||
const INACTIVE = {stringValue: "inactive", integerValue: 0} | ||
|
||
export {SOON, KIND_OF_SOON, NOT_SOON, INACTIVE}; |
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