@@ -20,6 +20,7 @@ function App() {
2020 const [ sortOption , setSortOption ] = useState ( 'recommended' ) ;
2121 const [ activeNav , setActiveNav ] = useState ( 'MEN' ) ;
2222 const [ sneakersView , setSneakersView ] = useState ( false ) ;
23+ const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
2324 const [ loggedInUser , setLoggedInUser ] = useState ( ( ) => {
2425 try { return JSON . parse ( localStorage . getItem ( 'zappify_user' ) ) || null ; } catch { return null ; }
2526 } ) ;
@@ -92,15 +93,19 @@ function App() {
9293 const sneakerMatch = sneakersView ? product . id >= 30 && product . id <= 44 : true ;
9394 const categoryMatch = selectedCategories . length === 0 || selectedCategories . includes ( product . category ) ;
9495 const themeMatch = selectedThemes . length === 0 || selectedThemes . includes ( product . theme ) ;
95- return sneakerMatch && categoryMatch && themeMatch ;
96+ const searchMatch = searchQuery . trim ( ) === '' ||
97+ product . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ||
98+ product . brand . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ||
99+ product . category . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ;
100+ return sneakerMatch && categoryMatch && themeMatch && searchMatch ;
96101 } ) ;
97102
98103 if ( sortOption === 'low-high' ) result = [ ...result ] . sort ( ( a , b ) => a . price - b . price ) ;
99104 else if ( sortOption === 'high-low' ) result = [ ...result ] . sort ( ( a , b ) => b . price - a . price ) ;
100105 else if ( sortOption === 'newest' ) result = [ ...result ] . sort ( ( a , b ) => b . id - a . id ) ;
101106
102107 return result ;
103- } , [ selectedCategories , selectedThemes , sortOption , sneakersView ] ) ;
108+ } , [ selectedCategories , selectedThemes , sortOption , sneakersView , searchQuery ] ) ;
104109
105110 return (
106111 < div className = "zappify-app" >
@@ -113,6 +118,8 @@ function App() {
113118 loggedInUser = { loggedInUser }
114119 onLogout = { handleLogout }
115120 onOpenAccount = { ( ) => setShowAccount ( true ) }
121+ searchQuery = { searchQuery }
122+ onSearch = { setSearchQuery }
116123 />
117124
118125 < main className = "app-main" >
0 commit comments