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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK
This commit is contained in:
leonarski_fandClaude Fable 5.1 committed 2026-11-13 00:31:48 +01:00
1 parent 0968981658
commit 10b1822ed1
2 files changed
+35 -10

No files matched your search

+25 -6
View File
@@ -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 <ThemeProvider theme={theme}>
<CssBaseline enableColorScheme/>
<Box sx={{ display: 'flex' }}>
<StatusBar s={s.broker} onMenuClick={toggleDrawer} mode={mode} onModeClick={toggleMode}/>
<StatusBar s={s.broker} drawerOpen={drawerOpen} onMenuClick={toggleDrawer} mode={mode} onModeClick={toggleMode}/>
{drawerOpen && (
<Drawer variant="permanent"
<Drawer variant={phone ? 'temporary' : 'permanent'} open onClose={closeDrawerOnPhone}
sx={{ width: drawerWidth, flexShrink: 0,
'& .MuiDrawer-paper': { width: drawerWidth, boxSizing: 'border-box',
bgcolor: drawer.bg, borderRight: 'none' } }}>
@@ -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' },
+10 -4
View File
@@ -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 <AppBar sx={{zIndex: (theme) => theme.zIndex.drawer + 1}}>
<Toolbar>
{onMenuClick && (
<IconButton color="inherit" edge="start" onClick={onMenuClick} sx={{mr: 2}}>
<MenuIcon/>
</IconButton>
<Tooltip title={drawerOpen ? "Hide the page list" : "Show the page list"}>
<IconButton color="inherit" edge="start" onClick={onMenuClick} sx={{mr: 2}}
aria-label={drawerOpen ? "Hide the page list" : "Show the page list"}>
{drawerOpen ? <MenuOpenIcon/> : <MenuIcon/>}
</IconButton>
</Tooltip>
)}
<Typography variant="h6" component="div" noWrap
sx={{flexGrow: 0.5, fontWeight: 500, letterSpacing: '.02em', display: {xs: 'none', sm: 'block'}}}>