Files
OpsLog/frontend/src/components/Menubar.tsx
T
rouggy 816a727e88 feat: stats timeline, band-map colours, frameless window, and four fixes
Statistics — the activity chart ignored the period selector: picking a year up
top left it showing the last 7 days, two controls contradicting each other. The
buttons were four fixed rolling windows anchored on the newest QSO, not
granularities. They now choose the BUCKET SIZE over the selected period, with an
Auto default and a step-up when a bucket would be too fine (the backend drops a
series past 750 buckets rather than ship 6000 unreadable bars). The hour-of-day
histogram covered a single day, too little to read anything from; it moves to
its own card with a weekday view, over the whole period.

Band map — the CW/data/phone sub-bands were shaded with the STATUS tokens, the
same amber that means "new band" on the pills drawn on top of them. A sub-band
is an identity, not a state: categorical hues now, validated in both themes
(violet failed on the dark steps — 1.9 ΔE from blue for a protan reader) and
added to the legend, since identity must never be colour-alone.

Frameless window — the OS title bar was a dead 32px band above a window that
already has its own. Minimise/maximise/close move into the app header, which
carries the drag region and double-click-to-maximise. The drag opt-out is by
ROLE in CSS, so a future button in that bar keeps working without anyone
remembering the rule.

Fixes:
- Saving settings froze the window while a device was slow: restarting a link
  waits for its poll goroutine, which can sit 45 s inside an uninterruptible COM
  Connect when another program holds the rig. The restart is now off the UI
  path; a slow one is logged.
- Multi-screen: a MAXIMISED window was never repositioned, so it came back on
  the primary screen every launch. The corner is now recorded even when
  maximised (it names the monitor) and re-applied while still hidden.
- The Callsign field is marked out at rest — operators were typing the call into
  Name, which sat beside it and looked identical.
- QSL dates get a real picker (native, for the OS calendar and locale order); a
  malformed old value stays in a text box rather than vanishing behind an empty
  one.

Also: a Support OpsLog entry in Help, and a WinKeyer protocol trace. The WK2
report (one element then a ten-second pause, sidetone that will not switch off)
is NOT fixed here: the WK1/WK2/WK3 command sets differ and a guessed fix would
break the operators it works for today. The trace logs every byte with the
command name and spells out the firmware family, which is what will settle it.
2026-07-27 20:50:44 +02:00

97 lines
3.7 KiB
TypeScript

import { useState } from 'react';
import {
DropdownMenu, DropdownMenuTrigger, DropdownMenuContent,
DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut,
} from '@/components/ui/dropdown-menu';
import { cn } from '@/lib/utils';
export type MenuItem =
// accent highlights an item that is an OFFER rather than a command (Donate).
// Generic on purpose: a hard-coded label test in the renderer would break the
// moment the menu is translated.
| { type: 'item'; label: string; action: string; shortcut?: string; disabled?: boolean; accent?: boolean }
| { type: 'separator' };
export interface Menu {
name: string;
label: string;
items: MenuItem[];
}
interface Props {
menus: Menu[];
onAction: (action: string) => void;
}
export function Menubar({ menus, onAction }: Props) {
// Track which menu is open so hover-to-switch works like a desktop menubar.
const [openMenu, setOpenMenu] = useState<string | null>(null);
return (
<nav className="flex items-stretch h-full">
{menus.map((menu) => (
<DropdownMenu
key={menu.name}
open={openMenu === menu.name}
onOpenChange={(o) => setOpenMenu(o ? menu.name : null)}
modal={false}
>
<DropdownMenuTrigger
onMouseEnter={() => {
// Only switch on hover if a menu is already open.
if (openMenu !== null && openMenu !== menu.name) setOpenMenu(menu.name);
}}
onPointerDown={(e) => {
// Desktop-menubar behaviour: when another menu is already
// open, a click on a different trigger should switch to it
// in one click. Without this Radix consumes the click to
// close the current menu first, requiring a second click
// to open the new one. We pre-empt by setting open state
// synchronously and stopping the event from reaching the
// default Radix toggle.
if (openMenu !== null && openMenu !== menu.name) {
e.preventDefault();
e.stopPropagation();
setOpenMenu(menu.name);
}
}}
className={cn(
'px-3 text-sm rounded-md text-muted-foreground hover:bg-muted hover:text-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring',
openMenu === menu.name && 'bg-muted text-primary',
)}
>
{menu.label}
</DropdownMenuTrigger>
<DropdownMenuContent
align="start" sideOffset={4} className="min-w-[240px]"
onCloseAutoFocus={(e) => {
// Radix re-focuses the trigger after close. Combined with our
// focus-visible:ring style this leaves an orange outline around
// the previously-clicked menu — looks like a stuck "selected"
// state. We swallow the auto-focus and let the next interaction
// decide where focus belongs.
e.preventDefault();
}}
>
{menu.items.map((item, i) =>
item.type === 'separator' ? (
<DropdownMenuSeparator key={i} />
) : (
<DropdownMenuItem
key={i}
disabled={item.disabled}
className={item.accent ? 'text-warning focus:text-warning font-medium' : undefined}
onSelect={() => onAction(item.action)}
>
<span>{item.label}</span>
{item.shortcut && <DropdownMenuShortcut>{item.shortcut}</DropdownMenuShortcut>}
</DropdownMenuItem>
),
)}
</DropdownMenuContent>
</DropdownMenu>
))}
</nav>
);
}