Files
TREK/client/src/mobile/keyboard/useShortcuts.ts
T
Maurice c204a25a9c feat(mobile): the touch shell laid out for iPad and unfolded foldables
The app shows the touch shell at every size now, an iPad's and an unfolded
foldable's included, instead of switching to the desktop pages from 768px.
One route tree survives rotation, Split View, Stage Manager and folding, and
the app's own features (Wallet, sharing into a trip, the edge swipe back)
are there on the big screen too.

Two size classes drive the layout (hooks/sizeClass.ts, Tailwind variants
wide: and split:):

- wide (600pt and taller than a phone on its side): a glass navigation rail
  on the leading edge replaces the dock and holds every destination with its
  name; sheets become centred form sheets; the trip's More menu is a popover
  beside the rail; lists keep a readable measure; dashboard, journey and
  vacay get columns; full-bleed maps run under the floating rail.
- split (900pt): the trip's plan, places or road trip chain sit in a pane
  beside the map, which follows the plan's day; the list/map switch hides
  and shows the pane like a sidebar; on a foldable that reports its fold the
  pane ends at the fold. Settings show their sections beside the page and the
  dashboard keeps its widgets in a column of their own.

A hardware keyboard gets the shortcuts an iPad app has (⌘1 to ⌘9 for the
sections, ⌘N, ⌘, , ⌥←/⌥→ through the days, ⌃⌘S for the pane, ⌘[ back),
answered by the page or, with a binary that has the keyCommands feature,
handed to it as native key commands.

The day strip fades at an edge that runs on, journey cards grow on a wide
window and a card without a photo takes the day's colour, and the Leaflet
map measures itself again when its box changes size.
2026-11-07 23:25:12 +01:00

28 lines
1.1 KiB
TypeScript

import { useEffect, useRef } from 'react';
import { useShortcutRegistry, type Shortcut } from './shortcuts';
/**
* Registers a screen's keyboard shortcuts while it is mounted (MKeyboardHost
* answers them). The list may be rebuilt on every render: the registry only
* changes when a shortcut's id, name or keys do, and pressing one always runs
* the newest handler.
*/
export function useShortcuts(owner: string, shortcuts: Shortcut[]): void {
const latest = useRef(shortcuts);
useEffect(() => {
latest.current = shortcuts;
});
const signature = shortcuts.map((s) => [s.id, s.title, s.key, s.mod, s.shift, s.alt, s.ctrl].join('|')).join('\n');
const setList = useShortcutRegistry((s) => s.set);
const remove = useShortcutRegistry((s) => s.remove);
// Re-registered when the signature changes, never for a new handler alone:
// each registered shortcut runs whatever handler is newest when pressed.
useEffect(() => {
setList(
owner,
latest.current.map((s) => ({ ...s, run: () => latest.current.find((x) => x.id === s.id)?.run() }))
);
}, [owner, signature, setList]);
useEffect(() => () => remove(owner), [owner, remove]);
}