Spaces:
Sleeping
Sleeping
File size: 1,707 Bytes
d97b8f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '@/lib/auth-context';
type ShortcutMap = {
[key: string]: () => void;
};
export const useKeyboardShortcuts = () => {
const navigate = useNavigate();
const { userData } = useAuth();
// Check if user is client role or not logged in
const isClientRole = !userData || userData?.roleName?.toLowerCase() === "client";
useEffect(() => {
// Don't set up shortcuts for client role users
if (isClientRole) {
return;
}
const shortcuts: ShortcutMap = {
// Alt+T for Tasks
'alt+t': () => navigate('/tasks'),
// Alt+F for Features
'alt+f': () => navigate('/issues'),
// Alt+D for Dashboard
'alt+d': () => navigate('/'),
// Alt+S for Settings
'alt+s': () => navigate('/settings'),
// Alt+B for Bugs
'alt+b': () => navigate('/bugs'),
// Alt+P for Projects
'alt+p': () => navigate('/projects'),
// Alt+E for Employee
'alt+e': () => navigate('/employee'),
};
const handleKeyDown = (event: KeyboardEvent) => {
// Check if Alt key is pressed
if (event.altKey) {
const key = event.key.toLowerCase();
const shortcutKey = `alt+${key}`;
if (shortcuts[shortcutKey]) {
event.preventDefault();
shortcuts[shortcutKey]();
}
}
};
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [navigate, isClientRole, userData]);
};
export default useKeyboardShortcuts; |