Skip to content

Commit cc3a247

Browse files
committed
refactor: move sidebar related components into app-sidebar
1 parent 15babd3 commit cc3a247

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
import { useLayout } from '@/context/layout-provider'
2-
import { Sidebar } from '@/components/ui/sidebar'
2+
import {
3+
Sidebar,
4+
SidebarContent,
5+
SidebarFooter,
6+
SidebarHeader,
7+
SidebarRail,
8+
} from '@/components/ui/sidebar'
9+
import { sidebarData } from './data/sidebar-data'
10+
import { NavGroup } from './nav-group'
11+
import { NavUser } from './nav-user'
12+
import { TeamSwitcher } from './team-switcher'
313

4-
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
14+
export function AppSidebar() {
515
const { collapsible, variant } = useLayout()
6-
return <Sidebar {...props} collapsible={collapsible} variant={variant} />
16+
return (
17+
<Sidebar collapsible={collapsible} variant={variant}>
18+
<SidebarHeader>
19+
<TeamSwitcher teams={sidebarData.teams} />
20+
</SidebarHeader>
21+
<SidebarContent>
22+
{sidebarData.navGroups.map((props) => (
23+
<NavGroup key={props.title} {...props} />
24+
))}
25+
</SidebarContent>
26+
<SidebarFooter>
27+
<NavUser user={sidebarData.user} />
28+
</SidebarFooter>
29+
<SidebarRail />
30+
</Sidebar>
31+
)
732
}

src/components/layout/authenticated-layout.tsx

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@ import { getCookie } from '@/lib/cookies'
33
import { cn } from '@/lib/utils'
44
import { LayoutProvider } from '@/context/layout-provider'
55
import { SearchProvider } from '@/context/search-provider'
6-
import {
7-
SidebarContent,
8-
SidebarFooter,
9-
SidebarHeader,
10-
SidebarInset,
11-
SidebarProvider,
12-
SidebarRail,
13-
} from '@/components/ui/sidebar'
6+
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'
147
import { AppSidebar } from '@/components/layout/app-sidebar'
158
import { SkipToMain } from '@/components/skip-to-main'
16-
import { sidebarData } from './data/sidebar-data'
17-
import { NavGroup } from './nav-group'
18-
import { NavUser } from './nav-user'
19-
import { TeamSwitcher } from './team-switcher'
209

2110
type AuthenticatedLayoutProps = {
2211
children?: React.ReactNode
@@ -26,23 +15,10 @@ export function AuthenticatedLayout({ children }: AuthenticatedLayoutProps) {
2615
const defaultOpen = getCookie('sidebar_state') !== 'false'
2716
return (
2817
<SearchProvider>
29-
<SidebarProvider defaultOpen={defaultOpen}>
30-
<LayoutProvider>
18+
<LayoutProvider>
19+
<SidebarProvider defaultOpen={defaultOpen}>
3120
<SkipToMain />
32-
<AppSidebar>
33-
<SidebarHeader>
34-
<TeamSwitcher teams={sidebarData.teams} />
35-
</SidebarHeader>
36-
<SidebarContent>
37-
{sidebarData.navGroups.map((props) => (
38-
<NavGroup key={props.title} {...props} />
39-
))}
40-
</SidebarContent>
41-
<SidebarFooter>
42-
<NavUser user={sidebarData.user} />
43-
</SidebarFooter>
44-
<SidebarRail />
45-
</AppSidebar>
21+
<AppSidebar />
4622
<SidebarInset
4723
className={cn(
4824
// Set content container, so we can use container queries
@@ -59,8 +35,8 @@ export function AuthenticatedLayout({ children }: AuthenticatedLayoutProps) {
5935
>
6036
{children ?? <Outlet />}
6137
</SidebarInset>
62-
</LayoutProvider>
63-
</SidebarProvider>
38+
</SidebarProvider>
39+
</LayoutProvider>
6440
</SearchProvider>
6541
)
6642
}

0 commit comments

Comments
 (0)