11import { useState , useMemo } from 'react'
22import Header from './components/Header'
3+ import Sidebar from './components/Sidebar'
34import ProductGrid from './components/ProductGrid'
45import ProductDetail from './components/ProductDetail'
56import { ALL_PRODUCTS } from './data/products'
@@ -9,13 +10,13 @@ import { useGoogleLogin } from '@react-oauth/google'
910import Checkout from './components/Checkout'
1011import AccountModal from './components/AccountModal'
1112
12- const CATEGORIES = [ 'All' , 'Men Low Top Sneakers' , 'Men High Top Sneakers' , 'Men Mid Top Sneakers' , 'Men Clogs' , 'Men Slip-ons' ] ;
13-
1413function App ( ) {
1514 const [ selectedCategories , setSelectedCategories ] = useState ( [ ] ) ;
15+ const [ selectedThemes , setSelectedThemes ] = useState ( [ ] ) ;
1616 const [ selectedProduct , setSelectedProduct ] = useState ( null ) ;
1717 const [ activeOverlay , setActiveOverlay ] = useState ( null ) ;
1818 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
19+ const [ activeNav , setActiveNav ] = useState ( 'MEN' ) ;
1920 const [ sneakersView , setSneakersView ] = useState ( false ) ;
2021 const [ showCheckout , setShowCheckout ] = useState ( false ) ;
2122 const [ showAccount , setShowAccount ] = useState ( false ) ;
@@ -55,10 +56,20 @@ function App() {
5556 setPlacedOrders ( [ ] ) ;
5657 } ;
5758
59+ const toggleFilter = ( item , type ) => {
60+ if ( type === 'category' ) {
61+ setSelectedCategories ( prev => prev . includes ( item ) ? prev . filter ( i => i !== item ) : [ ...prev , item ] ) ;
62+ } else {
63+ setSelectedThemes ( prev => prev . includes ( item ) ? prev . filter ( i => i !== item ) : [ ...prev , item ] ) ;
64+ }
65+ } ;
66+
5867 const handleNavigate = ( destination ) => {
5968 setSelectedProduct ( null ) ;
6069 setSelectedCategories ( [ ] ) ;
70+ setSelectedThemes ( [ ] ) ;
6171 setSneakersView ( destination === 'SNEAKERS' ) ;
72+ if ( destination !== 'home' ) setActiveNav ( destination ) ;
6273 } ;
6374
6475 const addToCart = ( product , size ) => {
@@ -96,13 +107,14 @@ function App() {
96107 return ALL_PRODUCTS . filter ( product => {
97108 const sneakerMatch = sneakersView ? product . id >= 30 && product . id <= 44 : true ;
98109 const categoryMatch = selectedCategories . length === 0 || selectedCategories . includes ( product . category ) ;
110+ const themeMatch = selectedThemes . length === 0 || selectedThemes . includes ( product . theme ) ;
99111 const searchMatch = searchQuery . trim ( ) === '' ||
100112 product . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ||
101113 product . brand . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ||
102114 product . category . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ;
103- return sneakerMatch && categoryMatch && searchMatch ;
115+ return sneakerMatch && categoryMatch && themeMatch && searchMatch ;
104116 } ) ;
105- } , [ selectedCategories , sneakersView , searchQuery ] ) ;
117+ } , [ selectedCategories , selectedThemes , sneakersView , searchQuery ] ) ;
106118
107119 return (
108120 < div className = "zappify-app" >
@@ -111,6 +123,7 @@ function App() {
111123 onNavigate = { handleNavigate }
112124 cartCount = { cartItems . reduce ( ( sum , i ) => sum + i . qty , 0 ) }
113125 wishlistCount = { wishlistItems . length }
126+ activeNav = { activeNav }
114127 loggedInUser = { loggedInUser }
115128 onOpenAccount = { ( ) => setShowAccount ( true ) }
116129 searchQuery = { searchQuery }
@@ -129,26 +142,19 @@ function App() {
129142 exit = { { opacity : 0 , x : - 20 } }
130143 transition = { { duration : 0.3 } }
131144 >
132- < div className = "category-chips" >
133- { CATEGORIES . map ( cat => (
134- < button
135- key = { cat }
136- className = { `cat-chip ${ selectedCategories . length === 0 && cat === 'All' ? 'active' : selectedCategories . includes ( cat ) ? 'active' : '' } ` }
137- onClick = { ( ) => cat === 'All'
138- ? setSelectedCategories ( [ ] )
139- : setSelectedCategories ( prev => prev . includes ( cat ) ? prev . filter ( c => c !== cat ) : [ ...prev , cat ] )
140- }
141- >
142- { cat }
143- </ button >
144- ) ) }
145+ < div className = "layout-split" >
146+ < Sidebar
147+ selectedCategories = { selectedCategories }
148+ selectedThemes = { selectedThemes }
149+ onToggleFilter = { toggleFilter }
150+ />
151+ < ProductGrid
152+ products = { filteredProducts }
153+ onProductClick = { setSelectedProduct }
154+ onToggleWishlist = { toggleWishlist }
155+ isWishlisted = { isWishlisted }
156+ />
145157 </ div >
146- < ProductGrid
147- products = { filteredProducts }
148- onProductClick = { setSelectedProduct }
149- onToggleWishlist = { toggleWishlist }
150- isWishlisted = { isWishlisted }
151- />
152158 </ motion . div >
153159 ) : (
154160 < motion . div
0 commit comments