-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: centralize keyboard shortcuts and fix bold shortcut conflic…
…ts (#8467) - Move keyboard shortcuts (Cmd+B for navigation, Cmd+/ for new conversation) to centralized hook - Disable default Cmd+B shortcut from Tiptap's Bold extension - Add custom Bold extension to prevent shortcut conflicts - Update Navigation component to receive isNavigationBarOpen state from parent Co-authored-by: Henry Fontanier <[email protected]>
- Loading branch information
1 parent
cf63e56
commit fbc10c8
Showing
5 changed files
with
57 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { LightWorkspaceType } from "@dust-tt/types"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useAppKeyboardShortcuts(owner: LightWorkspaceType) { | ||
const [isNavigationBarOpen, setIsNavigationBarOpen] = useState(true); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
function handleKeyboardShortcuts(event: KeyboardEvent) { | ||
// Check for Command/Control key | ||
const isModifier = event.metaKey || event.ctrlKey; | ||
|
||
if (isModifier) { | ||
switch (event.key) { | ||
case "b": | ||
event.preventDefault(); | ||
setIsNavigationBarOpen((prev) => !prev); | ||
break; | ||
|
||
case "/": | ||
event.preventDefault(); | ||
void router.push(`/w/${owner.sId}/assistant/new`); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener("keydown", handleKeyboardShortcuts); | ||
return () => window.removeEventListener("keydown", handleKeyboardShortcuts); | ||
}, [owner.sId, router]); | ||
|
||
return { isNavigationBarOpen, setIsNavigationBarOpen }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters