2023-09-07 18:12:45 +08:00
|
|
|
import { useCallback } from "react";
|
|
|
|
|
import { DEFAULT_SHORTCUTS } from "../config";
|
|
|
|
|
import { useSetting } from "./Setting";
|
|
|
|
|
|
|
|
|
|
export function useShortcut(action) {
|
|
|
|
|
const { setting, updateSetting } = useSetting();
|
|
|
|
|
const shortcuts = setting?.shortcuts || DEFAULT_SHORTCUTS;
|
2023-09-09 14:05:45 +08:00
|
|
|
const shortcut = shortcuts[action] || [];
|
2023-09-07 18:12:45 +08:00
|
|
|
|
|
|
|
|
const setShortcut = useCallback(
|
|
|
|
|
async (val) => {
|
2023-09-07 23:47:24 +08:00
|
|
|
Object.assign(shortcuts, { [action]: val });
|
|
|
|
|
await updateSetting({ shortcuts });
|
2023-09-07 18:12:45 +08:00
|
|
|
},
|
|
|
|
|
[action, shortcuts, updateSetting]
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-09 14:05:45 +08:00
|
|
|
return { shortcut, setShortcut };
|
2023-09-07 18:12:45 +08:00
|
|
|
}
|