wrolpi/app/src/components/KeyboardShortcutsProvider.js

249 lines
8.7 KiB
JavaScript
Raw Normal View History

2025-12-26 18:59:13 -07:00
import React, {useCallback, useEffect, useRef, useState} from "react";
import {useNavigate} from "react-router";
import {useHotkeys} from "react-hotkeys-hook";
import {KeyboardShortcutsContext} from "../contexts/KeyboardShortcutsContext";
ui: fix the cypress failures, and two real defects behind them All 43 cypress specs pass now (was 36 of 43). Five of the seven failures were stale selectors, two were real. Real, and both mine: The search modal stopped focusing its input. Mantine mounts modal content on a later tick, so the effect that focused it ran while the ref was still null; Semantic's modal mounted synchronously, which is why focusing there had been enough. Fixed declaratively -- the field asks for focus itself, and SearchBox also sets `data-autofocus`, which is what Mantine's focus trap honours when it takes focus away from a plain autoFocus. Escape closed the suggestion list and the enclosing modal at once, so a user correcting a mistyped query lost the whole modal. Escape now dismisses the suggestions and stops there; a second Escape, with the list closed, still closes the modal. Stale selectors, all in the specs: Semantic's icon font (`i.search.icon`) is SVG now, its `.ui.modal`/`.ui.dimmer` are the library's modal and overlay, and one test asserted a button carried the classes `ui button secondary`. That last one is rewritten to check what a user can actually perceive -- that Edit is a real link pointing at the edit route -- because framework class names say nothing and break on every library change. Two accessibility gaps the tests walked into: The nav's search control was an anchor with an onClick, no name and no keyboard path. It now has a name, a role and Enter/Space activation, which is also what let the spec stop matching on icon-font classes. The search dialog had no accessible name at all; it has one now. One `{force: true}` remains, with its reason recorded: Cypress judges that field covered because it sits in a fixed modal under a sticky header, and I verified by hand at Cypress's own viewport that it is the topmost element at its centre, unobscured, and focused on open. Also closed a hole in the ratchet that this uncovered. A file could drop its `semantic-ui-react` imports, leave the baseline, and still render Semantic through Theme.tsx's wrappers -- which is exactly how a Semantic modal survived in the search shortcut long after that file looked migrated. A test now forbids it, and the three files doing it (Calculators, KeyboardShortcutsProvider, and Common.js reaching for theme names) import from the library or from themes/names instead.
2026-07-30 12:53:19 -06:00
import {Modal} from "./ui";
2025-12-26 18:59:13 -07:00
import {SearchResultsInput} from "./Common";
import {useSearchSuggestions} from "./Search";
import HelpModal from "./HelpModal";
// Define all keyboard shortcuts with their metadata
export const SHORTCUTS = [
// Search & Help
{keys: 'meta+k, ctrl+k', description: 'Open search', category: 'Search'},
{keys: '/', description: 'Open search', category: 'Search', enableOnFormTags: false},
{keys: 'escape', description: 'Close modal', category: 'General'},
{keys: 'shift+/', description: 'Show keyboard shortcuts', category: 'Help'},
// Navigation (g+ sequences)
{keys: 'g h', description: 'Go to Home', category: 'Navigation', path: '/'},
{keys: 'g v', description: 'Go to Videos', category: 'Navigation', path: '/videos'},
{keys: 'g a', description: 'Go to Archives', category: 'Navigation', path: '/archives'},
2025-12-26 18:59:13 -07:00
{keys: 'g m', description: 'Go to Map', category: 'Navigation', path: '/map'},
{keys: 'g z', description: 'Go to Zim', category: 'Navigation', path: '/zim'},
{keys: 'g f', description: 'Go to Files', category: 'Navigation', path: '/files'},
{keys: 'g s', description: 'Go to Settings', category: 'Navigation', path: '/admin'},
{keys: 'g i', description: 'Go to Inventory', category: 'Navigation', path: '/inventory'},
// Page Search
{keys: 'f', description: 'Focus search input', category: 'Page Search'},
// Video Player
{keys: 'k', description: 'Play/pause video', category: 'Video Player'},
{keys: 'j', description: 'Jump back 15 seconds', category: 'Video Player'},
{keys: 'l', description: 'Jump forward 30 seconds', category: 'Video Player'},
{keys: 'n', description: 'Navigate to newer video', category: 'Video Player'},
{keys: 'p', description: 'Navigate to older video', category: 'Video Player'},
2026-03-27 17:59:36 -06:00
{keys: 'f', description: 'Toggle fullscreen', category: 'Video Player'},
2025-12-26 18:59:13 -07:00
];
function SearchModal({open, onClose}) {
const {
suggestionsResults,
handleResultSelect,
resultRenderer,
loading,
searchStr,
setSearchStr,
} = useSearchSuggestions();
const inputRef = useRef();
const prevOpen = useRef(open);
const localHandleResultSelect = (i) => {
onClose();
handleResultSelect(i);
};
useEffect(() => {
if (prevOpen.current === true && !open) {
// User has closed the modal.
setSearchStr('');
}
prevOpen.current = open;
}, [open, setSearchStr]);
useEffect(() => {
ui: fix the cypress failures, and two real defects behind them All 43 cypress specs pass now (was 36 of 43). Five of the seven failures were stale selectors, two were real. Real, and both mine: The search modal stopped focusing its input. Mantine mounts modal content on a later tick, so the effect that focused it ran while the ref was still null; Semantic's modal mounted synchronously, which is why focusing there had been enough. Fixed declaratively -- the field asks for focus itself, and SearchBox also sets `data-autofocus`, which is what Mantine's focus trap honours when it takes focus away from a plain autoFocus. Escape closed the suggestion list and the enclosing modal at once, so a user correcting a mistyped query lost the whole modal. Escape now dismisses the suggestions and stops there; a second Escape, with the list closed, still closes the modal. Stale selectors, all in the specs: Semantic's icon font (`i.search.icon`) is SVG now, its `.ui.modal`/`.ui.dimmer` are the library's modal and overlay, and one test asserted a button carried the classes `ui button secondary`. That last one is rewritten to check what a user can actually perceive -- that Edit is a real link pointing at the edit route -- because framework class names say nothing and break on every library change. Two accessibility gaps the tests walked into: The nav's search control was an anchor with an onClick, no name and no keyboard path. It now has a name, a role and Enter/Space activation, which is also what let the spec stop matching on icon-font classes. The search dialog had no accessible name at all; it has one now. One `{force: true}` remains, with its reason recorded: Cypress judges that field covered because it sits in a fixed modal under a sticky header, and I verified by hand at Cypress's own viewport that it is the topmost element at its centre, unobscured, and focused on open. Also closed a hole in the ratchet that this uncovered. A file could drop its `semantic-ui-react` imports, leave the baseline, and still render Semantic through Theme.tsx's wrappers -- which is exactly how a Semantic modal survived in the search shortcut long after that file looked migrated. A test now forbids it, and the three files doing it (Calculators, KeyboardShortcutsProvider, and Common.js reaching for theme names) import from the library or from themes/names instead.
2026-07-30 12:53:19 -06:00
/*
* Focus the search input when the modal opens.
*
* `autoFocus` on the input below is what actually does it: the modal mounts its
* content on a later tick, so this effect runs while `inputRef.current` is still
ui: the last of Semantic UI, in name and in dead CSS The library has been uninstalled for some time, but the codebase still read as though it were there: identifiers named after it, rules written against its class names, and about 180 comments explaining a rule in terms of a thing that is no longer installed. Renamed, keeping the vocabulary the app actually uses: semanticUIColorMap -> navColorHexMap, semanticColorNames -> paletteColorNames, semanticNames -> iconNameAliases, semanticSizes -> sizeAliases, and SemanticUIColors -> NavColors in wrolpi/schema.py, which is what validates nav_color on the way in. ColorToSemanticHexColor had no callers at all and is gone. The baseline ratchet has done its job -- the list reached zero, so the JSON is deleted and the guard keeps only the checks with teeth: no package, no import, no `className="ui "`, no toast library. Its Theme.tsx check went with the wrappers it was watching for. It also asserts its own walk found files, so a clean result cannot mean it scanned nothing. Deleted from App.css: every rule requiring `.ui`, `.inverted`, `.segment` or `.modal`, none of which any component has set since the stylesheet stopped loading, plus the form skeletons, ui-alerts and progress-text rules that nothing renders. Two of them were doing harm rather than nothing: the drag tints had a dark-theme variant under `.inverted` that stopped applying, leaving 15% of a fixed blue over a dark row, and now mix a token instead. Two selectors naming markup that no longer exists were live bugs. The file browser's filter had `.ui.input.file-browser-filter`, so it rendered at the browser default width on a bar laid out to give it 34em -- now qualified by its container, because `.wrolpi-action-input` sets `width: 100%` at the same specificity and is loaded later. And SearchBox takes named props rather than a rest spread, so the `id` DestinationForm hands it was dropped in silence and the label it renders pointed at nothing; the download forms' Destination field has had no associated label since the migration. "Semantic roles" survives in four places, where it means what it says. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 19:15:57 -06:00
* null. The modal this replaced mounted synchronously, which is why focusing here used
ui: fix the cypress failures, and two real defects behind them All 43 cypress specs pass now (was 36 of 43). Five of the seven failures were stale selectors, two were real. Real, and both mine: The search modal stopped focusing its input. Mantine mounts modal content on a later tick, so the effect that focused it ran while the ref was still null; Semantic's modal mounted synchronously, which is why focusing there had been enough. Fixed declaratively -- the field asks for focus itself, and SearchBox also sets `data-autofocus`, which is what Mantine's focus trap honours when it takes focus away from a plain autoFocus. Escape closed the suggestion list and the enclosing modal at once, so a user correcting a mistyped query lost the whole modal. Escape now dismisses the suggestions and stops there; a second Escape, with the list closed, still closes the modal. Stale selectors, all in the specs: Semantic's icon font (`i.search.icon`) is SVG now, its `.ui.modal`/`.ui.dimmer` are the library's modal and overlay, and one test asserted a button carried the classes `ui button secondary`. That last one is rewritten to check what a user can actually perceive -- that Edit is a real link pointing at the edit route -- because framework class names say nothing and break on every library change. Two accessibility gaps the tests walked into: The nav's search control was an anchor with an onClick, no name and no keyboard path. It now has a name, a role and Enter/Space activation, which is also what let the spec stop matching on icon-font classes. The search dialog had no accessible name at all; it has one now. One `{force: true}` remains, with its reason recorded: Cypress judges that field covered because it sits in a fixed modal under a sticky header, and I verified by hand at Cypress's own viewport that it is the topmost element at its centre, unobscured, and focused on open. Also closed a hole in the ratchet that this uncovered. A file could drop its `semantic-ui-react` imports, leave the baseline, and still render Semantic through Theme.tsx's wrappers -- which is exactly how a Semantic modal survived in the search shortcut long after that file looked migrated. A test now forbids it, and the three files doing it (Calculators, KeyboardShortcutsProvider, and Common.js reaching for theme names) import from the library or from themes/names instead.
2026-07-30 12:53:19 -06:00
* to be enough. The ref call is kept for the case where the modal is already
* mounted and merely re-opened.
*/
2025-12-26 18:59:13 -07:00
if (open && inputRef.current) {
inputRef.current.focus();
}
}, [open]);
if (!open) return null;
return (
ui: only the top modal answers Escape, and the audited widths Two things, both reported from the running app. Nested modals could not exist. Mantine binds a window-level keydown listener per open modal, gated only on whether that modal is open -- nothing checks which one the user is looking at: useWindowEvent('keydown', (event) => { if (event.key === 'Escape' && closeOnEscape && ... && opened) onClose(); }, {capture: true}); Two open modals meant two listeners, so one Escape closed both. Reproduced on the dashboard: the download modal plus the search modal over it, one press, both gone, back to the page. Both also sat at z-index 200, so which one drew on top was DOM order rather than which the user opened. Mantine's own answer is Modal.Stack with a stackId, which is the only thing that gates closeOnEscape. Not used, for two reasons: every call site would have to be rewritten to hoist its modal into a stack, and it sets `__hidden` on everything below the top -- the parent disappears while the child is open. The parent should be dimmed and still there, as it was before the migration. So the wrapper keeps the register itself: a module-level list of open modals, most recent on top, from which each modal takes closeOnEscape, trapFocus and a z-index two above its parent. Module-level rather than React context because the two modals in the bug are not nested in the JSX at all -- the search modal is rendered by KeyboardShortcutsProvider near the app root and the download modal by the dashboard. They are siblings that happen to be open together, and no context relates them. The increment is small on purpose: Mantine puts popovers at 300, and a stack that climbed past it would paint over the select dropdowns inside its own forms. Widths: Roland audited the modal list and chose sizes against Mantine's scale. Sixteen get wider -- twelve to `large` (620), four to `fullscreen` -- and eleven keep the width they had, with the size now written down so the decision is in the source rather than in a default. Flasher was passing Mantine's raw `sm`, which worked but bypassed the naming the audit used; it says `tiny` now. The size table itself is guarded, because it is the single thing that halved every modal during the migration and a quiet edit to it moves seventy at once. Semantic's widths, measured on the pre-migration build still running on the QA Pi: mini 360, tiny 540, small 720, large 1080, no-size 900. Mantine's, read out of its stylesheet: 320/380/440/620/780. A `small` modal went 720 -> 440 and one with no size went 900 -> 440. Three cases now hold the scale, the mapping, and the rule that no call site may name a size the table does not know -- an unknown name is passed to Mantine, ignored, and silently rendered at the default. Tested in a real browser: none of it is visible to jsdom -- the listener is on window with capture, the stacking is z-index, and "still visible behind" is geometry. Note that `should('be.visible')` is the wrong assertion for the parent: it is an occlusion check, so a child drawn correctly over its parent trips it. The test uses a wide viewport and asserts the parent is rendered and shows to both sides of the child. Planting the pre-fix behaviour reddens three. 1124 jest / 62 suites, 8 in modal-stack.cy.js, clean npm run build. The 12 failures in Tags/Channels/Download/Inventory.cy.js are the known pre-existing Semantic-era selector failures, unchanged.
2026-08-02 15:26:15 -06:00
<Modal size='small' open={open} onClose={onClose} centered={false} title='Search'>
2025-12-26 18:59:13 -07:00
<Modal.Content>
ui: the corner triggers, the More button, and the search modal Four faults, each measured in the running app before and after. The search glyph carried Semantic's `item` class, which has had no rules at all since Semantic was removed: no pointer cursor, no hover, and an 18.6px hit area against a 54.4px bar. It is the same kind of thing as Help and Admin and now takes the same class. The share glyph did compute `cursor: pointer` -- it is an `<a href>` -- but its target was the 24px box the icon occupies, so the pointer appeared only if you found it exactly. Corner anchors now stretch and pad like a link. The More button rendered with NO class at all: a bare grey UA button while the rest of the bar took the user's colour. Menu.Target clones its child and hands it a className of its own, and the trigger spread those cloned props after its own `className` attribute, so the clone replaced ours. It is merged now. This was mine, from extracting NavDropdownTrigger last commit -- and it also made the previous commit's "measured and drawn are the same component" claim only half true, because the hidden placeholder is not cloned and so kept its class. The bar still wrapped, for a reason the padding fix could not reach: the corner does not keep a constant width. The Cmd-K hint renders only once useKeyboardDetected has seen a keypress, so it appears at an arbitrary later moment and widens the corner by ~30px; the load, memory, temperature and drive warnings come and go with the machine's state. None of that resizes the container, which was the only thing observed -- so nothing recalculated. That is the other half of "at certain widths": the same viewport wrapped or not depending on whether the user had touched a key. The corner and the home link are observed too now. The search modal showed an input and the first line of the first group. The suggestion list is absolutely positioned, which is right everywhere else -- a list that reflows the page while you type is unusable -- but in a modal it fails twice: an absolute list adds no height, so the panel sized itself to the search box alone at 114px, and the panel's own `overflow: auto` then clipped the list at that edge. In the modal the list sits in flow; the inverse is asserted so the rule cannot leak to the pages where overlaying is correct. Two of the new tests were wrong first and reverting the fix left them green: they asserted hand-written markup carrying the classes I expected the components to have, rather than the real SearchIconButton and ShareButton. They use the real components now. Every fix was then planted against: 5 red for the More class, 2 for the search class, 2 for the corner hit area, 1 for the observer, 2 for the modal. 1115 jest / 62 suites, 196 in ui-layout.cy.js, clean npm run build. Confirmed live: share and search both pointer at 54.4px, More white on the bar colour with a transparent face, and the modal's list in flow and unclipped.
2026-08-02 14:45:49 -06:00
{/*
* `wrolpi-search-modal` makes the suggestion list part of the panel rather
* than an overlay on the page; see ui.css. Everywhere else the list floats
* over the page, which is right -- results that reflow the page while you
* type are unusable. Inside a modal it is wrong twice over: an absolutely
* positioned list adds no height, so the panel stayed 114px tall, and the
* panel's own `overflow: auto` then clipped the list at the panel's edge.
* The modal showed a search box and the first word of the first result.
*/}
<div className='wrolpi-search-modal'>
2025-12-26 18:59:13 -07:00
<SearchResultsInput
clearable
searchStr={searchStr}
onChange={setSearchStr}
onSubmit={setSearchStr}
size='large'
placeholder='Search everywhere...'
results={suggestionsResults}
handleResultSelect={localHandleResultSelect}
resultRenderer={resultRenderer}
loading={loading}
inputRef={inputRef}
ui: fix the cypress failures, and two real defects behind them All 43 cypress specs pass now (was 36 of 43). Five of the seven failures were stale selectors, two were real. Real, and both mine: The search modal stopped focusing its input. Mantine mounts modal content on a later tick, so the effect that focused it ran while the ref was still null; Semantic's modal mounted synchronously, which is why focusing there had been enough. Fixed declaratively -- the field asks for focus itself, and SearchBox also sets `data-autofocus`, which is what Mantine's focus trap honours when it takes focus away from a plain autoFocus. Escape closed the suggestion list and the enclosing modal at once, so a user correcting a mistyped query lost the whole modal. Escape now dismisses the suggestions and stops there; a second Escape, with the list closed, still closes the modal. Stale selectors, all in the specs: Semantic's icon font (`i.search.icon`) is SVG now, its `.ui.modal`/`.ui.dimmer` are the library's modal and overlay, and one test asserted a button carried the classes `ui button secondary`. That last one is rewritten to check what a user can actually perceive -- that Edit is a real link pointing at the edit route -- because framework class names say nothing and break on every library change. Two accessibility gaps the tests walked into: The nav's search control was an anchor with an onClick, no name and no keyboard path. It now has a name, a role and Enter/Space activation, which is also what let the spec stop matching on icon-font classes. The search dialog had no accessible name at all; it has one now. One `{force: true}` remains, with its reason recorded: Cypress judges that field covered because it sits in a fixed modal under a sticky header, and I verified by hand at Cypress's own viewport that it is the topmost element at its centre, unobscured, and focused on open. Also closed a hole in the ratchet that this uncovered. A file could drop its `semantic-ui-react` imports, leave the baseline, and still render Semantic through Theme.tsx's wrappers -- which is exactly how a Semantic modal survived in the search shortcut long after that file looked migrated. A test now forbids it, and the three files doing it (Calculators, KeyboardShortcutsProvider, and Common.js reaching for theme names) import from the library or from themes/names instead.
2026-07-30 12:53:19 -06:00
autoFocus
2025-12-26 18:59:13 -07:00
/>
ui: the corner triggers, the More button, and the search modal Four faults, each measured in the running app before and after. The search glyph carried Semantic's `item` class, which has had no rules at all since Semantic was removed: no pointer cursor, no hover, and an 18.6px hit area against a 54.4px bar. It is the same kind of thing as Help and Admin and now takes the same class. The share glyph did compute `cursor: pointer` -- it is an `<a href>` -- but its target was the 24px box the icon occupies, so the pointer appeared only if you found it exactly. Corner anchors now stretch and pad like a link. The More button rendered with NO class at all: a bare grey UA button while the rest of the bar took the user's colour. Menu.Target clones its child and hands it a className of its own, and the trigger spread those cloned props after its own `className` attribute, so the clone replaced ours. It is merged now. This was mine, from extracting NavDropdownTrigger last commit -- and it also made the previous commit's "measured and drawn are the same component" claim only half true, because the hidden placeholder is not cloned and so kept its class. The bar still wrapped, for a reason the padding fix could not reach: the corner does not keep a constant width. The Cmd-K hint renders only once useKeyboardDetected has seen a keypress, so it appears at an arbitrary later moment and widens the corner by ~30px; the load, memory, temperature and drive warnings come and go with the machine's state. None of that resizes the container, which was the only thing observed -- so nothing recalculated. That is the other half of "at certain widths": the same viewport wrapped or not depending on whether the user had touched a key. The corner and the home link are observed too now. The search modal showed an input and the first line of the first group. The suggestion list is absolutely positioned, which is right everywhere else -- a list that reflows the page while you type is unusable -- but in a modal it fails twice: an absolute list adds no height, so the panel sized itself to the search box alone at 114px, and the panel's own `overflow: auto` then clipped the list at that edge. In the modal the list sits in flow; the inverse is asserted so the rule cannot leak to the pages where overlaying is correct. Two of the new tests were wrong first and reverting the fix left them green: they asserted hand-written markup carrying the classes I expected the components to have, rather than the real SearchIconButton and ShareButton. They use the real components now. Every fix was then planted against: 5 red for the More class, 2 for the search class, 2 for the corner hit area, 1 for the observer, 2 for the modal. 1115 jest / 62 suites, 196 in ui-layout.cy.js, clean npm run build. Confirmed live: share and search both pointer at 54.4px, More white on the bar colour with a transparent face, and the modal's list in flow and unclipped.
2026-08-02 14:45:49 -06:00
</div>
2025-12-26 18:59:13 -07:00
</Modal.Content>
</Modal>
);
}
export function KeyboardShortcutsProvider({children}) {
const navigate = useNavigate();
const [searchModalOpen, setSearchModalOpen] = useState(false);
const [helpModalOpen, setHelpModalOpen] = useState(false);
const openSearchModal = useCallback(() => {
setHelpModalOpen(false);
setSearchModalOpen(true);
}, []);
const closeSearchModal = useCallback(() => {
setSearchModalOpen(false);
}, []);
const openHelpModal = useCallback(() => {
setSearchModalOpen(false);
setHelpModalOpen(true);
}, []);
const closeHelpModal = useCallback(() => {
setHelpModalOpen(false);
}, []);
const closeAllModals = useCallback(() => {
setSearchModalOpen(false);
setHelpModalOpen(false);
}, []);
// Search shortcuts - Cmd/Ctrl+K works everywhere
useHotkeys('meta+k, ctrl+k', (e) => {
e.preventDefault();
openSearchModal();
}, {
enableOnFormTags: true,
preventDefault: true,
});
// / for search - only when not in an input field
// Use 'Slash' (the keyboard code) for cross-browser compatibility
useHotkeys('Slash', (e) => {
// Only trigger for / not ? (shift+/)
if (e.shiftKey) return;
e.preventDefault();
openSearchModal();
}, {
enableOnFormTags: false,
});
// Escape closes any modal - works in inputs too
useHotkeys('escape', () => {
closeAllModals();
}, {
enableOnFormTags: true,
});
// ? for help modal - use shift+Slash
useHotkeys('shift+Slash', (e) => {
e.preventDefault();
openHelpModal();
}, {
enableOnFormTags: false,
preventDefault: true,
});
// Navigation shortcuts (g+ sequences) - custom implementation
// react-hotkeys-hook doesn't handle sequences well, so we implement our own
const gPressedRef = useRef(false);
const gTimeoutRef = useRef(null);
const NAV_KEYS = {
'h': '/',
'v': '/videos',
'a': '/archives',
2025-12-26 18:59:13 -07:00
'm': '/map',
'z': '/zim',
'f': '/files',
's': '/admin',
'i': '/inventory',
};
useEffect(() => {
const handleKeyDown = (e) => {
// Don't trigger in input fields
const tagName = e.target.tagName.toLowerCase();
if (tagName === 'input' || tagName === 'textarea' || tagName === 'select' || e.target.isContentEditable) {
return;
}
if (e.key === 'g' && !e.metaKey && !e.ctrlKey && !e.altKey) {
gPressedRef.current = true;
// Clear after 1 second
if (gTimeoutRef.current) clearTimeout(gTimeoutRef.current);
gTimeoutRef.current = setTimeout(() => {
gPressedRef.current = false;
}, 1000);
return;
}
if (gPressedRef.current && NAV_KEYS[e.key]) {
e.preventDefault();
gPressedRef.current = false;
if (gTimeoutRef.current) clearTimeout(gTimeoutRef.current);
navigate(NAV_KEYS[e.key]);
}
};
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
if (gTimeoutRef.current) clearTimeout(gTimeoutRef.current);
};
}, [navigate]);
const value = {
searchModalOpen,
setSearchModalOpen,
openSearchModal,
closeSearchModal,
helpModalOpen,
setHelpModalOpen,
openHelpModal,
closeHelpModal,
closeAllModals,
};
return (
<KeyboardShortcutsContext.Provider value={value}>
{children}
<SearchModal open={searchModalOpen} onClose={closeSearchModal}/>
<HelpModal open={helpModalOpen} onClose={closeHelpModal}/>
</KeyboardShortcutsContext.Provider>
);
}