useRealtimeInspectorShortcuts.ts42 lines · main
| 1 | import { SHORTCUT_IDS } from '@/state/shortcuts/registry' |
| 2 | import { useShortcut } from '@/state/shortcuts/useShortcut' |
| 3 | |
| 4 | interface UseRealtimeInspectorShortcutsParams { |
| 5 | hasChannel: boolean |
| 6 | isListening: boolean |
| 7 | onJoinChannel: () => void |
| 8 | onToggleFilters: () => void |
| 9 | onBroadcast: () => void |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Registers shortcuts scoped to the Realtime Inspector page: |
| 14 | * - Shift+J: open the join-channel popover |
| 15 | * - Shift+F: open the filter popover |
| 16 | * - Shift+B: open the broadcast message modal |
| 17 | * |
| 18 | * The Shift+L (toggle listening) shortcut is registered inside the Header |
| 19 | * component so it shares the start/stop handler — including temp-API-key |
| 20 | * refresh, permission gating, and telemetry — with the button click. |
| 21 | * |
| 22 | * Should be mounted once at the RealtimeInspector component level. |
| 23 | */ |
| 24 | export function useRealtimeInspectorShortcuts({ |
| 25 | hasChannel, |
| 26 | isListening, |
| 27 | onJoinChannel, |
| 28 | onToggleFilters, |
| 29 | onBroadcast, |
| 30 | }: UseRealtimeInspectorShortcutsParams) { |
| 31 | useShortcut(SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL, onJoinChannel, { |
| 32 | enabled: !hasChannel, |
| 33 | }) |
| 34 | |
| 35 | useShortcut(SHORTCUT_IDS.INSPECTOR_TOGGLE_FILTERS, onToggleFilters, { |
| 36 | enabled: hasChannel, |
| 37 | }) |
| 38 | |
| 39 | useShortcut(SHORTCUT_IDS.INSPECTOR_BROADCAST, onBroadcast, { |
| 40 | enabled: isListening, |
| 41 | }) |
| 42 | } |