|
3 | 3 | import { Menu, X, LogIn, ShoppingBag, Home } from 'lucide-react'; |
4 | 4 | import { useEffect, useMemo, useState } from 'react'; |
5 | 5 | import { useTranslations } from 'next-intl'; |
| 6 | +import { useSearchParams } from 'next/navigation'; |
6 | 7 | import { Link, usePathname } from '@/i18n/routing'; |
7 | 8 |
|
8 | 9 | import { SITE_LINKS } from '@/lib/navigation'; |
@@ -30,6 +31,8 @@ export function AppMobileMenu({ |
30 | 31 | const tCategories = useTranslations('shop.catalog.categories'); |
31 | 32 | const tProducts = useTranslations('shop.products'); |
32 | 33 | const pathname = usePathname(); |
| 34 | + const searchParams = useSearchParams(); |
| 35 | + const currentCategory = searchParams.get('category'); |
33 | 36 | const [open, setOpen] = useState(false); |
34 | 37 | const [isAnimating, setIsAnimating] = useState(false); |
35 | 38 |
|
@@ -59,10 +62,10 @@ export function AppMobileMenu({ |
59 | 62 | }, [open]); |
60 | 63 |
|
61 | 64 | const shopLinks = useMemo(() => [ |
62 | | - { href: '/shop/products', label: tProducts('title') }, |
63 | | - { href: '/shop/products?category=apparel', label: tCategories('apparel') }, |
64 | | - { href: '/shop/products?category=lifestyle', label: tCategories('lifestyle') }, |
65 | | - { href: '/shop/products?category=collectibles', label: tCategories('collectibles') }, |
| 65 | + { href: '/shop/products', label: tProducts('title'), category: null }, |
| 66 | + { href: '/shop/products?category=apparel', label: tCategories('apparel'), category: 'apparel' }, |
| 67 | + { href: '/shop/products?category=lifestyle', label: tCategories('lifestyle'), category: 'lifestyle' }, |
| 68 | + { href: '/shop/products?category=collectibles', label: tCategories('collectibles'), category: 'collectibles' }, |
66 | 69 | ], [tProducts, tCategories]); |
67 | 70 |
|
68 | 71 | const links = useMemo(() => { |
@@ -147,16 +150,20 @@ export function AppMobileMenu({ |
147 | 150 | <HeaderButton href="/" icon={Home} onClick={close}> |
148 | 151 | {t('home')} |
149 | 152 | </HeaderButton> |
150 | | - {links.map(link => ( |
151 | | - <Link |
152 | | - key={link.href} |
153 | | - href={link.href} |
154 | | - onClick={close} |
155 | | - className={linkClass(pathname === link.href)} |
156 | | - > |
157 | | - {'labelKey' in link ? t(link.labelKey) : link.label} |
158 | | - </Link> |
159 | | - ))} |
| 153 | + {links.map(link => { |
| 154 | + const isActive = pathname === '/shop/products' && |
| 155 | + ('category' in link ? link.category === currentCategory : currentCategory === null); |
| 156 | + return ( |
| 157 | + <Link |
| 158 | + key={link.href} |
| 159 | + href={link.href} |
| 160 | + onClick={close} |
| 161 | + className={linkClass(isActive)} |
| 162 | + > |
| 163 | + {'labelKey' in link ? t(link.labelKey) : link.label} |
| 164 | + </Link> |
| 165 | + ); |
| 166 | + })} |
160 | 167 | </> |
161 | 168 | ) : null} |
162 | 169 |
|
|
0 commit comments