File tree 4 files changed +8
-17
lines changed
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
49
49
'ziggy ' => fn (): array => [
50
50
...(new Ziggy )->toArray (),
51
51
'location ' => $ request ->url (),
52
- ]
52
+ ],
53
+ 'sidebarOpen ' => $ request ->cookie ('sidebar_state ' ) === 'true ' ,
53
54
];
54
55
}
55
56
}
Original file line number Diff line number Diff line change 14
14
health: '/up ' ,
15
15
)
16
16
->withMiddleware (function (Middleware $ middleware ) {
17
- $ middleware ->encryptCookies (except: ['appearance ' ]);
17
+ $ middleware ->encryptCookies (except: ['appearance ' , ' sidebar_state ' ]);
18
18
19
19
$ middleware ->web (append: [
20
20
HandleAppearance::class,
Original file line number Diff line number Diff line change 1
1
import { SidebarProvider } from '@/components/ui/sidebar' ;
2
- import { useState } from 'react' ;
2
+ import { SharedData } from '@/types' ;
3
+ import { usePage } from '@inertiajs/react' ;
3
4
4
5
interface AppShellProps {
5
6
children : React . ReactNode ;
6
7
variant ?: 'header' | 'sidebar' ;
7
8
}
8
9
9
10
export 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 ;
19
12
20
13
if ( variant === 'header' ) {
21
14
return < div className = "flex min-h-screen w-full flex-col" > { children } </ div > ;
22
15
}
23
16
24
- return (
25
- < SidebarProvider defaultOpen = { isOpen } open = { isOpen } onOpenChange = { handleSidebarChange } >
26
- { children }
27
- </ SidebarProvider >
28
- ) ;
17
+ return < SidebarProvider defaultOpen = { isOpen } > { children } </ SidebarProvider > ;
29
18
}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export interface SharedData {
27
27
quote : { message : string ; author : string } ;
28
28
auth : Auth ;
29
29
ziggy : Config & { location : string } ;
30
+ sidebarOpen : boolean ;
30
31
[ key : string ] : unknown ;
31
32
}
32
33
You can’t perform that action at this time.
0 commit comments