File tree Expand file tree Collapse file tree 4 files changed +8
-17
lines changed
Expand file tree Collapse file tree 4 files changed +8
-17
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ public function share(Request $request): array
4949 'ziggy ' => fn (): array => [
5050 ...(new Ziggy )->toArray (),
5151 'location ' => $ request ->url (),
52- ]
52+ ],
53+ 'sidebarOpen ' => $ request ->cookie ('sidebar_state ' ) === 'true ' ,
5354 ];
5455 }
5556}
Original file line number Diff line number Diff line change 1414 health: '/up ' ,
1515 )
1616 ->withMiddleware (function (Middleware $ middleware ) {
17- $ middleware ->encryptCookies (except: ['appearance ' ]);
17+ $ middleware ->encryptCookies (except: ['appearance ' , ' sidebar_state ' ]);
1818
1919 $ middleware ->web (append: [
2020 HandleAppearance::class,
Original file line number Diff line number Diff line change 11import { SidebarProvider } from '@/components/ui/sidebar' ;
2- import { useState } from 'react' ;
2+ import { SharedData } from '@/types' ;
3+ import { usePage } from '@inertiajs/react' ;
34
45interface AppShellProps {
56 children : React . ReactNode ;
67 variant ?: 'header' | 'sidebar' ;
78}
89
910export function AppShell ( { children, variant = 'header' } : AppShellProps ) {
10- const [ isOpen , setIsOpen ] = useState ( ( ) => ( typeof window !== 'undefined' ? localStorage . getItem ( 'sidebar' ) !== 'false' : true ) ) ;
11-
12- const handleSidebarChange = ( open : boolean ) => {
13- setIsOpen ( open ) ;
14-
15- if ( typeof window !== 'undefined' ) {
16- localStorage . setItem ( 'sidebar' , String ( open ) ) ;
17- }
18- } ;
11+ const isOpen = usePage < SharedData > ( ) . props . sidebarOpen ;
1912
2013 if ( variant === 'header' ) {
2114 return < div className = "flex min-h-screen w-full flex-col" > { children } </ div > ;
2215 }
2316
24- return (
25- < SidebarProvider defaultOpen = { isOpen } open = { isOpen } onOpenChange = { handleSidebarChange } >
26- { children }
27- </ SidebarProvider >
28- ) ;
17+ return < SidebarProvider defaultOpen = { isOpen } > { children } </ SidebarProvider > ;
2918}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export interface SharedData {
2727 quote : { message : string ; author : string } ;
2828 auth : Auth ;
2929 ziggy : Config & { location : string } ;
30+ sidebarOpen : boolean ;
3031 [ key : string ] : unknown ;
3132}
3233
You can’t perform that action at this time.
0 commit comments