Skip to content

Commit

Permalink
Favorites but expired items will be grey
Browse files Browse the repository at this point in the history
  • Loading branch information
TPH777 committed Jul 13, 2024
1 parent d579b6d commit 5bc6da0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/components/ConCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const ConCards = ({
{/* Map through the filtered food list and display each food item */}
{searchFoodList.map((food, index) => (
<Col key={index}>
<Card className="flex" key={food.id}>
<Card
className="flex"
bg={food.post ? "light" : "secondary"}
key={food.id}
>
<Card.Img variant="top" src={food.imageURL} /> {/* Food image */}
<Card.Body>
<Card.Title>{food.name}</Card.Title> {/* Food name */}
Expand Down
15 changes: 5 additions & 10 deletions src/pages/Favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export function FavoritePage() {
let navigate = useNavigate();
if (!user) {
navigate("/login");
return;
}
if (!isConsumer) {
navigate("/");
return;
}

const [foodList, setFoodList] = useState<FoodItem[]>([]); // State for user favorite food items
Expand All @@ -34,17 +36,10 @@ export function FavoritePage() {
setIsLoading(true);
try {
const updatedFoodList = await getFoodList();
const postedFoodList = updatedFoodList.filter(
(food) => food.post === true // posted items
const userFavList = await getFavFoodList(user); // Array of string of food.id of user favorites
const finalFoodList = updatedFoodList.filter(
(food) => userFavList.includes(food.id) // fav food items
);
let finalFoodList = postedFoodList;

if (user && isConsumer) {
const userFavList = await getFavFoodList(user); // Array of string of food.id of user favorites
finalFoodList = postedFoodList.filter(
(food) => userFavList.includes(food.id) // fav items
);
}
setFoodList(finalFoodList);
} catch (error) {
console.error("Error fetching food items:", error);
Expand Down

0 comments on commit 5bc6da0

Please sign in to comment.