Files
Sankofa/portal/src/hooks/useKeyboardShortcuts.ts
defiQUG 9daf1fd378 Apply Composer changes: comprehensive API updates, migrations, middleware, and infrastructure improvements
- Add comprehensive database migrations (001-024) for schema evolution
- Enhance API schema with expanded type definitions and resolvers
- Add new middleware: audit logging, rate limiting, MFA enforcement, security, tenant auth
- Implement new services: AI optimization, billing, blockchain, compliance, marketplace
- Add adapter layer for cloud integrations (Cloudflare, Kubernetes, Proxmox, storage)
- Update Crossplane provider with enhanced VM management capabilities
- Add comprehensive test suite for API endpoints and services
- Update frontend components with improved GraphQL subscriptions and real-time updates
- Enhance security configurations and headers (CSP, CORS, etc.)
- Update documentation and configuration files
- Add new CI/CD workflows and validation scripts
- Implement design system improvements and UI enhancements
2025-12-12 18:01:35 -08:00

82 lines
2.1 KiB
TypeScript

'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
interface KeyboardShortcut {
key: string;
ctrlKey?: boolean;
shiftKey?: boolean;
altKey?: boolean;
action: () => void;
description: string;
}
export function useKeyboardShortcuts(shortcuts: KeyboardShortcut[]) {
const router = useRouter();
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
// Don't trigger shortcuts when typing in inputs
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement ||
(event.target instanceof HTMLElement && event.target.isContentEditable)
) {
return;
}
for (const shortcut of shortcuts) {
if (
event.key === shortcut.key &&
(shortcut.ctrlKey === undefined || event.ctrlKey === shortcut.ctrlKey) &&
(shortcut.shiftKey === undefined || event.shiftKey === shortcut.shiftKey) &&
(shortcut.altKey === undefined || event.altKey === shortcut.altKey)
) {
event.preventDefault();
shortcut.action();
break;
}
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [shortcuts]);
}
export function useGlobalKeyboardShortcuts() {
const router = useRouter();
useKeyboardShortcuts([
{
key: '/',
action: () => {
const searchInput = document.querySelector('input[type="search"]') as HTMLInputElement;
if (searchInput) {
searchInput.focus();
}
},
description: 'Focus search',
},
{
key: 'g',
ctrlKey: true,
action: () => router.push('/dashboard'),
description: 'Go to dashboard',
},
{
key: '?',
action: () => {
// Show keyboard shortcuts help
const helpModal = document.getElementById('keyboard-shortcuts-help');
if (helpModal) {
(helpModal as any).showModal?.();
}
},
description: 'Show keyboard shortcuts',
},
]);
}