Skip to content

Commit 84e8562

Browse files
committed
Address sidebar edge cases with UX
1 parent 63038a8 commit 84e8562

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

ui/src/components/Sidebar.astro

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const categoryOrder = ["syntax", "data_structures", "classes", "advanced"];
3838
(function() {
3939
const stored = localStorage.getItem('sidebar-collapsed');
4040
const isMobile = window.innerWidth < 900;
41-
const isCollapsed = stored === 'true' || (stored === null && isMobile);
41+
const isCollapsed = isMobile || stored === 'true';
4242
if (isCollapsed) {
4343
const container = document.querySelector('.app-container');
4444
if (container) {
@@ -372,7 +372,6 @@ const categoryOrder = ["syntax", "data_structures", "classes", "advanced"];
372372
right: 0;
373373
bottom: 0;
374374
background-color: rgba(0, 0, 0, 0.4);
375-
backdrop-filter: blur(2px);
376375
z-index: 999;
377376
}
378377
}
@@ -467,7 +466,7 @@ const categoryOrder = ["syntax", "data_structures", "classes", "advanced"];
467466
// Load initial state
468467
const stored = localStorage.getItem('sidebar-collapsed');
469468
const isMobile = window.innerWidth < 900;
470-
const isCollapsed = stored === 'true' || (stored === null && isMobile);
469+
const isCollapsed = isMobile || stored === 'true';
471470
if (isCollapsed) {
472471
container.classList.add('sidebar-collapsed');
473472
} else {
@@ -490,21 +489,27 @@ const categoryOrder = ["syntax", "data_structures", "classes", "advanced"];
490489

491490
// Auto-collapse/expand on window resize transition
492491
let lastWidth = window.innerWidth;
492+
let resizeTimer: any;
493493
window.addEventListener('resize', () => {
494+
document.documentElement.classList.add('no-transition');
495+
494496
const currentWidth = window.innerWidth;
495497
const wasDesktop = lastWidth >= 900;
496498
const isMobile = currentWidth < 900;
497499

498500
if (wasDesktop && isMobile) {
499501
container.classList.add('sidebar-collapsed');
500502
} else if (!wasDesktop && !isMobile) {
501-
const stored = localStorage.getItem('sidebar-collapsed');
502-
const isCollapsed = stored === 'true';
503-
if (!isCollapsed) {
504-
container.classList.remove('sidebar-collapsed');
505-
}
503+
// Always expand the sidebar on desktop width and save state
504+
container.classList.remove('sidebar-collapsed');
505+
localStorage.setItem('sidebar-collapsed', 'false');
506506
}
507507
lastWidth = currentWidth;
508+
509+
clearTimeout(resizeTimer);
510+
resizeTimer = window.setTimeout(() => {
511+
document.documentElement.classList.remove('no-transition');
512+
}, 100);
508513
});
509514
}
510515

ui/src/layouts/Layout.astro

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const lang = getLangFromUrl(Astro.url);
1212
---
1313

1414
<!doctype html>
15-
<html lang={lang}>
15+
<html lang={lang} class="no-transition">
1616
<head>
1717
<meta charset="UTF-8" />
1818
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -33,3 +33,18 @@ const lang = getLangFromUrl(Astro.url);
3333
<slot />
3434
</body>
3535
</html>
36+
37+
<script>
38+
// Remove the no-transition class once the initial layout has settled
39+
document.addEventListener('astro:page-load', () => {
40+
requestAnimationFrame(() => {
41+
document.documentElement.classList.remove('no-transition');
42+
});
43+
});
44+
45+
// Re-apply no-transition before a page transition begins
46+
document.addEventListener('astro:before-preparation', () => {
47+
document.documentElement.classList.add('no-transition');
48+
});
49+
</script>
50+

ui/src/styles/global.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ a:hover {
9191
.animate-fade-in {
9292
animation: fadeIn 0.3s ease-out forwards;
9393
}
94+
95+
/* Prevent transition flashes on page load, navigation, and window resize */
96+
.no-transition,
97+
.no-transition * {
98+
transition: none !important;
99+
}
100+

0 commit comments

Comments
 (0)