diff --git a/client/src/pages/DogList.jsx b/client/src/pages/DogList.jsx index d1e6aed..1815348 100644 --- a/client/src/pages/DogList.jsx +++ b/client/src/pages/DogList.jsx @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom' import { Dog, Plus, Search, Calendar, Hash, ArrowRight } from 'lucide-react' import axios from 'axios' import DogForm from '../components/DogForm' +import { ChampionBadge, ChampionBloodlineBadge } from '../components/ChampionBadge' function DogList() { const [dogs, setDogs] = useState([]) @@ -12,13 +13,8 @@ function DogList() { const [loading, setLoading] = useState(true) const [showAddModal, setShowAddModal] = useState(false) - useEffect(() => { - fetchDogs() - }, []) - - useEffect(() => { - filterDogs() - }, [dogs, search, sexFilter]) + useEffect(() => { fetchDogs() }, []) + useEffect(() => { filterDogs() }, [dogs, search, sexFilter]) const fetchDogs = async () => { try { @@ -33,24 +29,19 @@ function DogList() { const filterDogs = () => { let filtered = dogs - if (search) { filtered = filtered.filter(dog => dog.name.toLowerCase().includes(search.toLowerCase()) || (dog.registration_number && dog.registration_number.toLowerCase().includes(search.toLowerCase())) ) } - if (sexFilter !== 'all') { filtered = filtered.filter(dog => dog.sex === sexFilter) } - setFilteredDogs(filtered) } - const handleSave = () => { - fetchDogs() - } + const handleSave = () => { fetchDogs() } const calculateAge = (birthDate) => { if (!birthDate) return null @@ -58,17 +49,16 @@ function DogList() { const birth = new Date(birthDate) let years = today.getFullYear() - birth.getFullYear() let months = today.getMonth() - birth.getMonth() - - if (months < 0) { - years-- - months += 12 - } - + if (months < 0) { years--; months += 12 } if (years === 0) return `${months}mo` if (months === 0) return `${years}y` return `${years}y ${months}mo` } + // A dog has champion blood if sire or dam is a champion + const hasChampionBlood = (dog) => + (dog.sire && dog.sire.is_champion) || (dog.dam && dog.dam.is_champion) + if (loading) { return
Loading dogs...
} @@ -109,12 +99,9 @@ function DogList() { {(search || sexFilter !== 'all') && ( -