feat: retain side nav collapse/expand status between sessions (#714)

Stores the collapse vs expand status of the side navigation in local storage so it's carried across browser windows/sessions.

Ref: HDX-1539
This commit is contained in:
Dan Hable 2025-03-26 09:18:03 -05:00 committed by GitHub
parent e884d85354
commit 957925131d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
"@hyperdx/app": minor
---
Stores the collapse vs expand status of the side navigation in local storage so it's carried across browser windows/sessions.

View file

@ -372,12 +372,13 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
);
const { width } = useWindowSize();
const [isPreferCollapsed, setIsPreferCollapsed] = useState<
undefined | boolean
>(undefined);
const [isPreferCollapsed, setIsPreferCollapsed] = useLocalStorage<boolean>(
'isNavCollapsed',
false,
);
const isSmallScreen = (width ?? 1000) < 900;
const isCollapsed = isPreferCollapsed ?? isSmallScreen;
const isCollapsed = isSmallScreen || isPreferCollapsed;
const navWidth = isCollapsed ? 50 : 230;
@ -595,7 +596,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
className={isCollapsed ? 'mt-4' : ''}
style={{ marginRight: -4 }}
title="Collapse/Expand Navigation"
onClick={() => setIsPreferCollapsed(v => !v)}
onClick={() => setIsPreferCollapsed((v: boolean) => !v)}
>
<i className="bi bi-layout-sidebar"></i>
</Button>