useRealtimeInspectorShortcuts.ts 1.2 KB

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