From f2be6d7f9f0005345d5ea0d8547b8244d9c58599 Mon Sep 17 00:00:00 2001 From: Mahasvin24 Date: Sun, 20 Aug 2023 14:02:36 -0700 Subject: [PATCH] Working Search + Bug Fixes --- app/page.tsx | 1 + components/Search.tsx | 58 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 3ab954d..c46117d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -48,6 +48,7 @@ const dogBreeds = [ "Golden Retriever", "Great Dane", "Havanese", + "Husky", "Labrador Retriever", "Maltese", "Mastiff", diff --git a/components/Search.tsx b/components/Search.tsx index 0a1433e..ede3245 100644 --- a/components/Search.tsx +++ b/components/Search.tsx @@ -50,7 +50,9 @@ const Search = (props: any) => { const hermitCrabBreeds = props.hermitCrabBreeds; const ageTypes = props.ageTypes; - let [selectedAnimal, setSelectedAnimal] = useState("None"); + let [selectedAnimal, setSelectedAnimal] = useState("Species (Any)"); + let [selectedBreed, setSelectedBreed] = useState("Breed (Any)"); + let [selectedAge, setSelectedAge] = useState("Age (Any)"); const [pets, setPets] = useState([]); useEffect(() => { @@ -92,9 +94,47 @@ const Search = (props: any) => { case "Hermit Crabs": return hermitCrabBreeds; default: - return []; + return ["Breed (Any)"]; } } + + function sortPets(pet) { + //Testing Statements + // console.log("Selected Animal: " + selectedAnimal + " | Pet Species: " + pet.species); + // console.log("Selected Breed: " + selectedBreed + " | Pet Breed: " + pet.breed); + // console.log("Selected Age: " + selectedAge + " | Pet Age: " + pet.age.toString()); + + //Fixing Selected Animal Formatting + let testingSelectedAnimal = selectedAnimal.trim(); + if (selectedAnimal.indexOf(")") !== -1) { testingSelectedAnimal = testingSelectedAnimal.substring(0, testingSelectedAnimal.indexOf("(")).trim() } + testingSelectedAnimal = testingSelectedAnimal.substring(0, testingSelectedAnimal.lastIndexOf("s")); + + + + console.log("Testing Selected Animal: " + testingSelectedAnimal); + if ( + (selectedAnimal === "Species (Any)" || testingSelectedAnimal === pet.species) && + (selectedBreed === "Breed (Any)" || selectedBreed === pet.breed) && + (selectedAge === "Age (Any)" || selectedAge === pet.age.toString()) + ) { + return ( + + ); + } + return null; + } return ( ); }