mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 21:29:08 +03:00
* decouple editor panel from global state * refactor again * dont close assistant * remove async * onsave props * Fix TS errors * Remove editorPanel state from app-state, use useHotKey hooks for keyboard shortcuts * Minor UX improvements to EditorPanel --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
21 lines
490 B
TypeScript
21 lines
490 B
TypeScript
import { useEffect } from 'react'
|
|
|
|
export function useHotKey(
|
|
callback: (e: KeyboardEvent) => void,
|
|
key: string,
|
|
dependencies: any[] = []
|
|
): void {
|
|
useEffect(() => {
|
|
function handler(e: KeyboardEvent) {
|
|
if ((e.metaKey || e.ctrlKey) && e.key === key && !e.altKey && !e.shiftKey) {
|
|
callback(e)
|
|
}
|
|
}
|
|
|
|
window.addEventListener('keydown', handler)
|
|
return () => {
|
|
window.removeEventListener('keydown', handler)
|
|
}
|
|
}, [key, ...dependencies])
|
|
}
|