1212 let modules = $derived (data ?.allModules || []);
1313
1414 // Track if module panel is open
15- let isModulesPanelOpen = $state (window . innerWidth >= 768 );
16-
15+ let isModulesPanelOpen = $state (false );
16+
1717 // On mobile, the sidebar is fixed position and overlays the content
18- let isMobile = $state (window .innerWidth < 768 );
19-
20- // Update mobile status on resize
21- function handleResize() {
22- const newIsMobile = window .innerWidth < 768 ;
23- if (newIsMobile !== isMobile ) {
24- isMobile = newIsMobile ;
25- }
26-
27- // Automatically close sidebar on mobile when resizing down
28- if (isMobile && isModulesPanelOpen && window .innerWidth < 480 ) {
29- isModulesPanelOpen = false ;
30- }
31-
32- // Automatically open sidebar on desktop
33- if (! isMobile && ! isModulesPanelOpen ) {
34- isModulesPanelOpen = true ;
18+ let isMobile = $state (false );
19+ let windowWidth = $state (0 );
20+
21+ // Use a derived value instead of an event listener
22+ $effect (() => {
23+ if (windowWidth > 0 ) {
24+ // Only run this when windowWidth has been set (client-side)
25+ isMobile = windowWidth < 768 ;
26+
27+ // Auto close on very small screens
28+ if (isMobile && isModulesPanelOpen && windowWidth < 480 ) {
29+ isModulesPanelOpen = false ;
30+ }
31+
32+ // Auto open on desktop
33+ if (! isMobile && ! isModulesPanelOpen ) {
34+ isModulesPanelOpen = true ;
35+ }
3536 }
36- }
37-
37+ });
38+
3839 onMount (() => {
40+ windowWidth = window .innerWidth ;
41+ isModulesPanelOpen = window .innerWidth >= 768 ;
42+
43+ const handleResize = () => {
44+ windowWidth = window .innerWidth ;
45+ };
46+
3947 window .addEventListener (' resize' , handleResize );
4048 return () => {
4149 window .removeEventListener (' resize' , handleResize );
4856 }
4957 </script >
5058
51- <div class =" relative flex h-full w-full flex-col md:flex-row gap-2 sm:gap-4 p-1 sm:p-2 md:p-4 overflow-hidden" >
59+ <div
60+ class =" relative flex h-full w-full flex-col gap-2 overflow-hidden p-1 sm:gap-4 sm:p-2 md:flex-row md:p-4"
61+ >
5262 <!-- Overlay for mobile when sidebar is open -->
5363 {#if isMobile && isModulesPanelOpen }
54- <div
55- class =" fixed inset-0 bg-black bg-opacity-50 z-20"
56- onclick ={toggleModulesPanel }
57- ></div >
64+ <div class ="fixed inset-0 z-20 bg-black bg-opacity-50" onclick ={toggleModulesPanel }></div >
5865 {/if }
5966
6067 <!-- Modules Sidebar - Fixed on mobile, normal on desktop -->
6168 <div
62- class =" sidebar-container transition-all duration-300 z-30 "
69+ class =" sidebar-container z-30 transition-all duration-300"
6370 class:fixed ={isMobile }
6471 class:inset-y- 0={isMobile }
6572 class:left- 0={isMobile }
6673 class:w- 64={isModulesPanelOpen }
6774 class:w- 0={!isModulesPanelOpen }
6875 class:md:relative ={true }
6976 >
70- <div
71- class =" h-full overflow-hidden transition-all duration-300 bg-surface-100 dark:bg-surface-800 rounded-r-lg shadow-lg "
72- class:w- 64={isModulesPanelOpen }
77+ <div
78+ class =" h-full overflow-hidden rounded-r-lg bg-surface-100 shadow-lg transition-all duration-300 dark:bg-surface-800"
79+ class:w- 64={isModulesPanelOpen }
7380 class:w- 0={!isModulesPanelOpen }
7481 >
7582 {#if isModulesPanelOpen }
113120 </div >
114121
115122 <!-- Main Content Area - Full width on mobile -->
116- <div class =" flex-1 rounded-lg overflow-hidden" >
123+ <div class =" flex-1 overflow-hidden rounded-lg " >
117124 {@render children ?.()}
118125 </div >
119126</div >
123130 :global(body .sidebar-open ) {
124131 overflow : hidden ;
125132 }
126-
133+
127134 /* Ensure the parent container fills available height */
128135 :global(html , body , .app-shell , .app-shell-content ) {
129136 height : 100% ;
130137 overflow-x : hidden ;
131138 }
132- </style >
139+ </style >
0 commit comments