Skip to content

Commit

Permalink
feat(#13): apply css to urgency labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dterceroparker committed Sep 18, 2024
1 parent e097d2f commit 6307f89
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
6 changes: 1 addition & 5 deletions src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
} from 'firebase/firestore';
import { useEffect, useState } from 'react';
import { db } from './config';
import {
getFutureDate,
cal,
calculateDaysDifferenceFromNowculateDaysDifferenceFromNow,
} from '../utils';
import { getFutureDate, calculateDaysDifferenceFromNow } from '../utils';
import { calculateEstimate } from '@the-collab-lab/shopping-list-utils';
/**
* A custom hook that subscribes to the user's shopping lists in our Firestore
Expand Down
25 changes: 25 additions & 0 deletions src/components/ListItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ th {
background-color: #3e27ed;
border-bottom: 2px solid #ddd;
}

.duesoon {
color: orange;
font-weight: bold;
}

.duekindofsoon {
color: yellow;
font-weight: bold;
}

.notduesoon {
color: green;
font-weight: bold;
}

.nolongeractive {
color: gray;
font-weight: bold;
}

.overdue {
color: red;
font-weight: bold;
}
4 changes: 3 additions & 1 deletion src/components/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function ListItem({
}
};

const urgencyClass = sortCriteria.tag.toLowerCase().replace(/\s/g, '');

return (
<>
<tr className="ListItem">
Expand All @@ -76,7 +78,7 @@ export function ListItem({
<td>
{dateLastPurchased ? dateLastPurchased.toDate().toLocaleString() : ''}
</td>
<td>{sortCriteria.tag}</td>
<td className={urgencyClass}>{sortCriteria.tag}</td>
</tr>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function comparePurchaseUrgency(list) {
};
inactive.push(item);
} else if (days < 60 && days > 0) {
item.sortCriteria = { tag: 'Past due date', daysUntilNextPurchase: days };
item.sortCriteria = { tag: 'Overdue', daysUntilNextPurchase: days };
overdue.push(item);
} else if (days <= 0 && days >= -7) {
item.sortCriteria = { tag: 'Due soon', daysUntilNextPurchase: days };
Expand All @@ -49,7 +49,7 @@ export function comparePurchaseUrgency(list) {
};
future.push(item);
} else if (days < -30) {
item.sortCriteria = { tag: 'Due not soon', daysUntilNextPurchase: days };
item.sortCriteria = { tag: 'Not due soon', daysUntilNextPurchase: days };
future.push(item);
}
});
Expand Down
37 changes: 4 additions & 33 deletions src/views/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export function List({ data, listPath }) {
<table>
<thead>
<tr>
<th>Product</th>
<th>Buy Now</th>
<th>Last Purchase Date</th>
<th>Urgency</th>
<th scope="col">Product</th>
<th scope="col">Buy Now</th>
<th scope="col">Last Purchase Date</th>
<th scope="col">Urgency</th>
</tr>
</thead>
<tbody>
Expand All @@ -84,32 +84,3 @@ export function List({ data, listPath }) {
</>
);
}
{
/* <ul>
{filterList.length ? (
filterList.map((item) => {
return (
<ListItem
key={item.id}
name={item.name}
itemId={item.id}
listPath={listPath}
totalPurchases={item.totalPurchases}
dateLastPurchased={item.dateLastPurchased}
purchaseInterval={item.purchaseInterval}
dateCreated={item.dateCreated}
sortCriteria={item.sortCriteria}
/>
);
})
) : (
<li>
{' '}
No items found! <NavLink to="/manage-list"> Add item</NavLink>
</li>
)}
</ul> */
}
// </>
// );
// }

0 comments on commit 6307f89

Please sign in to comment.