import { useState } from 'react'; import { Link } from 'react-router-dom'; import { Heart, Tag, Trash2, Filter, ChevronDown } from 'lucide-react'; const Favorites = () => { const [favorites, setFavorites] = useState([ { id: 0, title: 'Dell XPS 16 Laptop', price: 850, category: 'Electronics', image: '/image1.avif', condition: 'Like New', seller: 'Michael T.', datePosted: '5d ago', dateAdded: '2023-03-08', }, ]); const [showFilters, setShowFilters] = useState(false); const [sortBy, setSortBy] = useState('dateAdded'); const [filterCategory, setFilterCategory] = useState('All'); // Function to remove item from favorites const removeFromFavorites = (id) => { setFavorites(favorites.filter(item => item.id !== id)); }; // Available categories for filtering const categories = ['All', 'Electronics', 'Textbooks', 'Furniture', 'Kitchen', 'Other']; // Sort favorites based on selected sort option const sortedFavorites = [...favorites].sort((a, b) => { if (sortBy === 'dateAdded') { return new Date(b.dateAdded) - new Date(a.dateAdded); } else if (sortBy === 'priceHigh') { return b.price - a.price; } else if (sortBy === 'priceLow') { return a.price - b.price; } return 0; }); // Filter favorites based on selected category const filteredFavorites = filterCategory === 'All' ? sortedFavorites : sortedFavorites.filter(item => item.category === filterCategory); return (
Items you save will appear here. Start browsing to add items to your favorites.
Browse Listings