spacedrive/interface/hooks/useKeybindEventHandler.ts
Brendan Allan ae31e10e0b
[ENG-1436] Store search state in search params (#1795)
* source search query from search params

* store filters in search params with round trip

* the rest bc apparently i forgot some?

* remove all references to overview

* add /:libraryId redirect
2023-11-17 21:07:33 +00:00

38 lines
1 KiB
TypeScript

import { useEffect } from 'react';
import { useNavigate } from 'react-router';
import { KeybindEvent } from '../util/keybind';
import { getWindowState } from './useWindowState';
export const useKeybindEventHandler = (libraryId?: string) => {
const navigate = useNavigate();
const windowState = getWindowState();
useEffect(() => {
const handler = (e: KeybindEvent) => {
e.preventDefault();
switch (e.detail.action) {
case 'open_settings':
libraryId && navigate(`/${libraryId}/settings/client/general`);
break;
// case 'open_overview':
// libraryId && navigate(`/${libraryId}/overview`);
// break;
case 'open_search':
// somehow emit ctrl/cmd+f
break;
case 'window_fullscreened':
windowState.isFullScreen = true;
break;
case 'window_not_fullscreened':
windowState.isFullScreen = false;
break;
}
};
document.addEventListener('keybindexec', handler);
return () => document.removeEventListener('keybindexec', handler);
}, [navigate, libraryId, windowState]);
};