From d1af53fbecfef98361cd5cf63e174d5c499acc6f Mon Sep 17 00:00:00 2001 From: TPH777 Date: Sat, 13 Jul 2024 18:51:42 +0800 Subject: [PATCH] Added fav count beside HeartSwitch --- src/components/ConCards.tsx | 19 +++++++++++++------ src/interface/FoodItem.ts | 1 + src/pages/Dashboard.tsx | 4 +++- src/pages/Favorites.tsx | 28 +++++++++++++++------------- src/pages/Home.tsx | 28 ++++++++++++++++++++++++---- 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/components/ConCards.tsx b/src/components/ConCards.tsx index c56690d..0ff6172 100644 --- a/src/components/ConCards.tsx +++ b/src/components/ConCards.tsx @@ -1,4 +1,4 @@ -import { Badge, Card, Col, Row } from "react-bootstrap"; +import { Badge, Card, Col, Container, Row } from "react-bootstrap"; import { timestampToString } from "../functions/Date"; import { HeartSwitch } from "@anatoliygatt/heart-switch"; import { FoodItem } from "../interface/FoodItem"; @@ -53,11 +53,18 @@ export const ConCards = ({ {food.business} {/* HeartSwitch to toggle favorite status */} - toggleFavorite(food.id)} - /> + + + + toggleFavorite(food.id)} + /> + + {food.favoriteCount || 0} + + diff --git a/src/interface/FoodItem.ts b/src/interface/FoodItem.ts index 0be8f87..a5770e0 100644 --- a/src/interface/FoodItem.ts +++ b/src/interface/FoodItem.ts @@ -9,4 +9,5 @@ export interface FoodItem { business: string; // Name of the business posted the food item imageURL: string; // URL to the image of the food item imagePath: string; // Path to access the image of the food item in firebase storage + favoriteCount: number; } diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index 24a7141..ed35774 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -19,9 +19,11 @@ export function Dashboard() { let navigate = useNavigate(); if (!user) { navigate("/login"); + return; } if (isConsumer) { navigate("/"); + return; } const [isAdding, setIsAdding] = useState(false); // State for adding a new food item @@ -107,7 +109,7 @@ export function Dashboard() { {!isLoading && !isAdding && !isEditing && ( <> -

{user?.displayName}'s Dashboard

+

{user.displayName}'s Dashboard

{/* Button to add new food */}