Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

677 B
Raw Blame
import { SHORTCUT_OPTIONS, isPlainKeyPress, openDialogCount } from './shortcut-guards'
import { SHORTCUTS, shortcutBinding } from './registry'
import { useShortcutsEnabled } from './useShortcutsEnabled'
import type { TaskShortcutsArgs } from './shortcuts.types'

export function useTaskShortcuts(args: TaskShortcutsArgs) {
  const enabled = useShortcutsEnabled()

  function toggleComplete(event: KeyboardEvent) {
    if (!enabled.value || !isPlainKeyPress(event) || !args.canToggleComplete.value) return
    if (openDialogCount() > 1) return
    args.toggleComplete()
  }

  defineShortcuts({ [shortcutBinding(SHORTCUTS.toggleComplete)]: toggleComplete }, SHORTCUT_OPTIONS)
}