import Mousetrap from "mousetrap";
export function useKeyboard() {
const [, setVisible] = useRecoilState(GlobalUserOpenState);
const [, setOpen] = useRecoilState(GlobalDocSerachOpen);
const [, setGlobalDocSearchOptions] = useRecoilState(GlobalDocSearchOptions);
const [, setGlobalDocSerachCustomColumns] = useRecoilState(GlobalDocSerachCustomColumns);
const [, setOpenSearch] = useRecoilState(GlobalSearchOpenState); // 全局搜索
// 监听快捷键
useEffect(() => {
// 全局用户搜索
Mousetrap.bind("u", function () {
setVisible((value: boolean) => !value);
});
// 全局文档搜索
Mousetrap.bind("s", function () {
setOpen((value: boolean) => !value);
setGlobalDocSerachCustomColumns(() => []);
setGlobalDocSearchOptions(() => undefined);
});
// 大搜
Mousetrap.bind(["command+k", "ctrl+k"], function () {
setOpenSearch(true);
});
});
}