lots of UI changes, and keyboard command support

This commit is contained in:
Sriram Hariharan
2023-03-04 22:42:51 -06:00
parent 00b8cd74b6
commit bc464cd264
9 changed files with 143 additions and 24 deletions

View File

@@ -0,0 +1,20 @@
import { useEffect } from 'react';
/**
* Hook that calls a callback when a key is pressed
* @param key the key to listen for
* @param callback the callback to call when the key is pressed
*/
export function useKeyPress(key: string, callback: (...args: any[]) => void): void {
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === key) {
callback();
}
};
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [key, callback]);
}