From 10b1822ed16e32fbfe5fd327c88098398166eb68 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 13 Nov 2026 00:31:48 +0100 Subject: [PATCH] frontend: the page list can be hidden, and the choice is kept The drawer with the page list takes 240 px that the rugnux live page is better off having. The menu button in the top bar already hid it, but nothing said so: it now has a tooltip and its icon shows the state (the open-menu glyph while the list is shown), and the choice is kept per browser in localStorage, so a screen set up for the live page stays that way across reloads. The plots and the Mol* stage already redraw to their box through their ResizeObservers. On a phone the permanent drawer squeezed the page to 150 px until it was closed: below the sm breakpoint it is now a temporary drawer that starts closed, lies over the page when opened, and closes on a tap outside or on choosing a page; the kept choice applies to wider screens only. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK --- frontend/src/App.tsx | 31 +++++++++++++++++++++------ frontend/src/components/StatusBar.tsx | 14 ++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index b73aa5b25..8e8c70422 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -2,7 +2,7 @@ import { ReactNode, useCallback, useMemo, useState } from 'react'; import { Box, CssBaseline, Drawer, Grid, Link, List, ListItemButton, - ListItemIcon, ListItemText, ListSubheader, Stack, ThemeProvider, Toolbar, + ListItemIcon, ListItemText, ListSubheader, Stack, ThemeProvider, useMediaQuery, } from "@mui/material"; import { useQuery } from "@tanstack/react-query"; @@ -65,6 +65,19 @@ import licenseMd from "../../docs/LICENSE.md?raw"; const drawerWidth = 240; +// Whether the drawer with the page list is shown; the menu button in the top bar toggles it, and the choice +// is kept per browser (the rugnux live page is one to watch with the drawer away). On a phone the drawer +// lies over the page instead, so it starts closed there whatever was kept. +const DRAWER_KEY = "jfjoch-drawer-open"; + +function storedDrawerOpen(): boolean { + try { + return localStorage.getItem(DRAWER_KEY) !== "closed"; + } catch { + return true; + } +} + // PSI branding sits alone in the footer credit bar with clear space (never merged // with the app wordmark or menu icon). The four official logos differ only in the // diffused spots; pick one at module load so it is fixed per page load and never @@ -132,13 +145,19 @@ function MarkdownDoc({ md }: { md: string }) { } function App() { - const [drawerOpen, setDrawerOpen] = useState(true); const [view, setView] = useState('dashboard'); const [mode, toggleMode] = useColourMode(); const theme = useMemo(() => makeTheme(mode), [mode]); const drawer = drawerColours(mode); + const phone = useMediaQuery(theme.breakpoints.down('sm')); + const [drawerOpen, setDrawerOpen] = useState(() => !phone && storedDrawerOpen()); - const toggleDrawer = useCallback(() => setDrawerOpen(o => !o), []); + const toggleDrawer = useCallback(() => setDrawerOpen(o => { + if (!phone) + try { localStorage.setItem(DRAWER_KEY, o ? "closed" : "open"); } catch { /* private window */ } + return !o; + }), [phone]); + const closeDrawerOnPhone = useCallback(() => { if (phone) setDrawerOpen(false); }, [phone]); // Poll general statistics once per second; structural sharing keeps unchanged // slices referentially stable so memoized panels only re-render when their own @@ -264,9 +283,9 @@ function App() { return - + {drawerOpen && ( - @@ -284,7 +303,7 @@ function App() { ? { component: 'a', href: it.href, target: '_blank', rel: 'noopener' } : { selected: view === it.id, - onClick: () => setView(it.id) })} + onClick: () => { setView(it.id); closeDrawerOnPhone(); } })} sx={{ borderLeft: '4px solid transparent', '&.Mui-selected': { bgcolor: drawer.selected, borderColor: 'secondary.main' }, diff --git a/frontend/src/components/StatusBar.tsx b/frontend/src/components/StatusBar.tsx index a231f5a6d..0353dd9fe 100644 --- a/frontend/src/components/StatusBar.tsx +++ b/frontend/src/components/StatusBar.tsx @@ -8,6 +8,7 @@ import Box from '@mui/material/Box'; import Stack from '@mui/material/Stack'; import {indigo, deepOrange} from '@mui/material/colors'; import MenuIcon from '@mui/icons-material/Menu'; +import MenuOpenIcon from '@mui/icons-material/MenuOpen'; import KeyIcon from '@mui/icons-material/Key'; import LightModeIcon from '@mui/icons-material/LightMode'; import DarkModeIcon from '@mui/icons-material/DarkMode'; @@ -19,6 +20,8 @@ import {getToken, setToken, useTokenRequired} from "../auth"; type MyProps = { s?: broker_status; + // whether the drawer with the page list is shown, and the button that hides or shows it + drawerOpen?: boolean; onMenuClick?: () => void; // the colour mode the app is in, and the switch to the other one mode?: 'light' | 'dark'; @@ -144,7 +147,7 @@ export function StatusBarSpacer() { ; } -function StatusBar({s, onMenuClick, mode, onModeClick}: MyProps) { +function StatusBar({s, drawerOpen, onMenuClick, mode, onModeClick}: MyProps) { // Pick each button's tier from the current state, so the one action that makes // sense right now is lime and the rest recede. const st = s?.state; @@ -178,9 +181,12 @@ function StatusBar({s, onMenuClick, mode, onModeClick}: MyProps) { return theme.zIndex.drawer + 1}}> {onMenuClick && ( - - - + + + {drawerOpen ? : } + + )}