⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
import { useEffect } from 'react';
import type { WorkItemsView } from '@/utils/viewTypes';
import { isTypingTarget, type HotkeyId } from '@/utils/hotkeys';
import { useHotkeyMatch } from '@/context/useHotkeys';
// The layout hotkeys, paired with the view each one opens.
const VIEW_HOTKEYS: [HotkeyId, WorkItemsView][] = [
['view.kanban', 'kanban'],
['view.table', 'table'],
['view.timeline', 'timeline'],
['view.calendar', 'calendar'],
];
// The global keyboard layer. Which combination runs what is declared in
// lib/hotkeys; this hook only decides when a binding may fire. A 'global' binding
// (the palette) fires even with an overlay open, while an 'app' one is suppressed
// while the user types or an overlay is open, because its combination is a plain
// key that would land in the text being typed.
export function useKeyboardShortcuts(opts: {
hasProject: boolean;
// Whether this project has a chat panel to show at all.
hasChat: boolean;
// True while any modal/overlay is open, which suppresses the app bindings.
overlayOpen: boolean;
onToggleCommand: () => void;
onChangeView: (view: WorkItemsView) => void;
onNewIssue: () => void;
onNewInitiative: () => void;
onNewProject: () => void;
onSettings: () => void;
onToggleChat: () => void;
}) {
const {
hasProject,
hasChat,
overlayOpen,
onToggleCommand,
onChangeView,
onNewIssue,
onNewInitiative,
onNewProject,
onSettings,
onToggleChat,
} = opts;
const matches = useHotkeyMatch();
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (matches(e, 'palette.toggle')) {
e.preventDefault();
onToggleCommand();
return;
}
if (isTypingTarget(e.target) || overlayOpen) return;
if (hasProject) {
for (const [id, view] of VIEW_HOTKEYS) {
if (matches(e, id)) {
e.preventDefault();
onChangeView(view);
return;
}
}
}
if (hasProject && matches(e, 'issue.new')) {
e.preventDefault();
onNewIssue();
return;
}
if (hasProject && matches(e, 'initiative.new')) {
e.preventDefault();
onNewInitiative();
return;
}
if (matches(e, 'project.new')) {
e.preventDefault();
onNewProject();
return;
}
if (hasProject && matches(e, 'project.settings')) {
e.preventDefault();
onSettings();
return;
}
if (hasChat && matches(e, 'chat.toggle')) {
e.preventDefault();
onToggleChat();
}
}
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, [
hasProject,
hasChat,
overlayOpen,
matches,
onToggleCommand,
onChangeView,
onNewIssue,
onNewInitiative,
onNewProject,
onSettings,
onToggleChat,
]);
}