Skip to content

Commit

Permalink
Removed uncesscary function and variables. Changed name of the state …
Browse files Browse the repository at this point in the history
…variable to make more specific and clear.
  • Loading branch information
Tyler Jordan Wright committed Nov 25, 2020
1 parent 6e6492b commit a6d8132
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/components/ItemTable/ItemTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { ArrowDownward, ArrowUpward } from "@material-ui/icons";
export default function ItemTable({ data }) {
const [selectedRow, setSelecetedRow] = useState({ queue: null, number: null });

const [background, setBackground] = useState("#ffffff");
const [cellBackgroundColor, setCellBackgroundColor] = useState("#ffffff");

const setStyle = (background) => {
setBackground(background);
};


const LastUpdatedCell = ({ time }) => {
const lastUpdated = new Date(time).getTime();
Expand All @@ -24,14 +22,15 @@ export default function ItemTable({ data }) {
const week = 7 * day;
const month = 4 * week;

setStyle("red");

if (timeDelta > day && timeDelta < week && timeDelta < month) {
setStyle("yellow");
} else if (timeDelta > week && timeDelta < month) {
setStyle("purple");
} else if (timeDelta > month) {
setStyle("green");
if (timeDelta > day && timeDelta < week && timeDelta < month)//more than one day since last
{
setCellBackgroundColor("yellow");
} else if (timeDelta > week && timeDelta < month) // more than a week since last update
{
setCellBackgroundColor("purple");
} else if (timeDelta > month) //more than a month since last update
{
setCellBackgroundColor("green");
}
return(
<RelativeTime value={time} />
Expand Down Expand Up @@ -165,7 +164,7 @@ export default function ItemTable({ data }) {
{row.cells.map(cell => (
<TableCell classes={{ root: classes.columnBorders }} {...cell.getCellProps(
{
style:{backgroundColor: cell.column.id==='lastUpdated' ? background : null}
style:{backgroundColor: cell.column.id==='lastUpdated' ? cellBackgroundColor : null}
},
)}>
{cell.render("Cell")}
Expand Down

0 comments on commit a6d8132

Please sign in to comment.