import { useState, useEffect } from "react"; import { Link, useNavigate } from "react-router-dom"; import { Tag, Book, Laptop, Sofa, Utensils, Gift, Heart } from "lucide-react"; const Home = () => { const navigate = useNavigate(); const [listings, setListings] = useState([]); const [error, setError] = useState(null); useEffect(() => { const fetchProducts = async () => { try { const response = await fetch( "http://localhost:3030/api/product/get_product" ); if (!response.ok) throw new Error("Failed to fetch products"); const data = await response.json(); if (data.success) { setListings( data.data.map((product) => ({ id: product.ProductID, title: product.Name, price: product.Price, category: product.CategoryID, image: product.ImageURL, condition: "New", // Modify based on actual data seller: "Unknown", // Modify if seller info is available datePosted: "Just now", isFavorite: false, })) ); } else { throw new Error(data.message || "Error fetching products"); } } catch (error) { console.error("Error fetching products:", error); setError(error.message); } }; fetchProducts(); }, []); // Toggle favorite status const toggleFavorite = (id, e) => { e.preventDefault(); // Prevent navigation when clicking the heart icon setListings((prevListings) => prevListings.map((listing) => listing.id === id ? { ...listing, isFavorite: !listing.isFavorite } : listing ) ); }; const handleSelling = () => { navigate("/selling"); }; return (
{/* Hero Section with School Background */}
{/* Background Image - Positioned at bottom */}
University of Calgary {/* Dark overlay for better text readability */}
{/* Content */}

Buy and Sell on Campus

The marketplace exclusively for university students. Find everything you need or sell what you don't.

{/* Categories */} {/*

Categories

{categories.map((category) => ( ))}
*/} {/* Recent Listings */}

Recent Listings

{listings.map((listing) => (
{listing.title}

{listing.title}

${listing.price}
{listing.category} {listing.condition}
{listing.datePosted} {listing.seller}
))}
); }; export default Home;