From 29cd44888e117240601d0c06eeaa587bcf6acd3c Mon Sep 17 00:00:00 2001 From: Jacob Calvillo Date: Tue, 26 Mar 2024 16:28:29 -0600 Subject: [PATCH] adding search bar --- .../Products/BrandViewer/BrandContainer.jsx | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/pages/Products/BrandViewer/BrandContainer.jsx b/src/pages/Products/BrandViewer/BrandContainer.jsx index 0bb2a64..360d11a 100644 --- a/src/pages/Products/BrandViewer/BrandContainer.jsx +++ b/src/pages/Products/BrandViewer/BrandContainer.jsx @@ -2,10 +2,13 @@ import { useEffect, useState } from 'react'; import { filterBrandsByType, getAllBrands } from '../../../services/BrandService'; import { getImageURLFromStorage } from '../../../services/Firebase/storage'; import BrandList from './BrandList'; +import { Input } from '@mui/material'; const BrandContainer = ({ onBrandSelect }) => { const [automotiveBrands, setAutomotiveBrands] = useState([]); const [heavyDutyBrands, setHeavyDutyBrands] = useState([]); + const [searchTerm, setSearchTerm] = useState(''); + const [filteredBrands, setFilteredBrands] = useState({ automotive: [], heavyDuty: [] }); useEffect(() => { const fetchBrands = async () => { @@ -49,10 +52,33 @@ const BrandContainer = ({ onBrandSelect }) => { fetchBrands(); }, []); + useEffect(() => { + const filterBrands = () => { + const filteredAutomotiveBrands = automotiveBrands.filter(brand => + brand.name.toLowerCase().includes(searchTerm.toLowerCase()) + ); + const filteredHeavyDutyBrands = heavyDutyBrands.filter(brand => + brand.name.toLowerCase().includes(searchTerm.toLowerCase()) + ); + setFilteredBrands({ automotive: filteredAutomotiveBrands, heavyDuty: filteredHeavyDutyBrands }); + }; + + filterBrands(); + }, [searchTerm, automotiveBrands, heavyDutyBrands]); + + const handleSearchChange = (e) => { + setSearchTerm(e.target.value); + }; + return (
- - + + +
); };