Skip to content

Commit e5de3d7

Browse files
committed
fix: mobile navigation
1 parent 9aaf6b1 commit e5de3d7

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use client';
2+
3+
import { CaretDownIcon } from '@phosphor-icons/react';
4+
import { usePathname } from 'next/navigation';
5+
import { useMemo } from 'react';
6+
import { Button } from '@/components/ui/button';
7+
import {
8+
DropdownMenu,
9+
DropdownMenuContent,
10+
DropdownMenuItem,
11+
DropdownMenuTrigger,
12+
} from '@/components/ui/dropdown-menu';
13+
import { useWebsites } from '@/hooks/use-websites';
14+
import { cn } from '@/lib/utils';
15+
import {
16+
getDefaultCategory,
17+
getNavigationWithWebsites,
18+
} from './navigation-config';
19+
20+
interface MobileCategorySelectorProps {
21+
onCategoryChange?: (categoryId: string) => void;
22+
selectedCategory?: string;
23+
}
24+
25+
export function MobileCategorySelector({
26+
onCategoryChange,
27+
selectedCategory,
28+
}: MobileCategorySelectorProps) {
29+
const pathname = usePathname();
30+
const { websites, isLoading: isLoadingWebsites } = useWebsites();
31+
32+
const { categories, defaultCategory } = useMemo(() => {
33+
const config = getNavigationWithWebsites(
34+
pathname,
35+
websites,
36+
isLoadingWebsites
37+
);
38+
const defaultCat = getDefaultCategory(pathname);
39+
return { categories: config.categories, defaultCategory: defaultCat };
40+
}, [pathname, websites, isLoadingWebsites]);
41+
42+
const activeCategory = selectedCategory || defaultCategory;
43+
const currentCategory = categories.find((cat) => cat.id === activeCategory);
44+
45+
return (
46+
<div className="border-border border-b p-3 md:hidden">
47+
<DropdownMenu>
48+
<DropdownMenuTrigger asChild>
49+
<Button
50+
className="flex h-10 w-full items-center justify-between px-3"
51+
type="button"
52+
variant="outline"
53+
>
54+
<div className="flex items-center gap-2">
55+
{currentCategory?.icon && (
56+
<currentCategory.icon className="h-4 w-4" weight="duotone" />
57+
)}
58+
<span>{currentCategory?.name || 'Select Category'}</span>
59+
</div>
60+
<CaretDownIcon className="h-4 w-4" weight="fill" />
61+
</Button>
62+
</DropdownMenuTrigger>
63+
<DropdownMenuContent className="w-full min-w-[var(--radix-dropdown-menu-trigger-width)]">
64+
{categories.map((category) => {
65+
const Icon = category.icon;
66+
const isActive = activeCategory === category.id;
67+
return (
68+
<DropdownMenuItem
69+
className={cn(
70+
'flex cursor-pointer items-center gap-2',
71+
isActive && 'bg-muted'
72+
)}
73+
key={category.id}
74+
onClick={() => onCategoryChange?.(category.id)}
75+
>
76+
<Icon
77+
className={cn(
78+
'h-4 w-4',
79+
isActive ? 'text-primary' : 'text-muted-foreground'
80+
)}
81+
weight={isActive ? 'fill' : 'duotone'}
82+
/>
83+
<span>{category.name}</span>
84+
</DropdownMenuItem>
85+
);
86+
})}
87+
</DropdownMenuContent>
88+
</DropdownMenu>
89+
</div>
90+
);
91+
}

apps/dashboard/components/layout/sidebar.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAccordionStates } from '@/hooks/use-persistent-state';
1111
import { useWebsites } from '@/hooks/use-websites';
1212
import { cn } from '@/lib/utils';
1313
import { CategorySidebar } from './category-sidebar';
14+
import { MobileCategorySelector } from './navigation/mobile-category-selector';
1415
import {
1516
getDefaultCategory,
1617
getNavigationWithWebsites,
@@ -161,7 +162,7 @@ export function Sidebar() {
161162
<ListIcon className="h-5 w-5" weight="duotone" />
162163
</Button>
163164

164-
<Link
165+
<Link
165166
className="flex items-center gap-2 transition-opacity hover:opacity-80"
166167
href="/websites"
167168
>
@@ -231,6 +232,12 @@ export function Sidebar() {
231232
<div className="flex h-full flex-col">
232233
{header}
233234

235+
{/* Mobile Category Selector */}
236+
<MobileCategorySelector
237+
onCategoryChange={setSelectedCategory}
238+
selectedCategory={selectedCategory}
239+
/>
240+
234241
<nav aria-label="Main navigation" className="flex flex-col">
235242
{navigation.map((section) => (
236243
<NavigationSection

0 commit comments

Comments
 (0)