Add a global command palette powered by TanStack Hotkeys#10
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a cmdk-based command palette with global hotkeys and hotkeys devtools, injects a HotkeysProvider, adds a themed Sonner toaster, expands Tauri fullscreen capabilities, refactors theme resolution to include a system-aware resolved theme, auto-initializes/disposes projects store, and wires a sidebar toggle event. Changes
Sequence DiagramsequenceDiagram
participant User as User
participant Hotkeys as HotkeysProvider
participant Palette as CommandPalette
participant Theme as ThemeContext
participant Tauri as TauriWindow
participant Sidebar as SidebarComponent
User->>Hotkeys: press Mod+K
Hotkeys->>Palette: emit toggle
Palette->>Palette: setIsOpen(true)
Palette-->>User: show dialog
User->>Palette: select "Toggle Theme"
Palette->>Theme: toggleThemePreference()
Theme->>Theme: update preference & compute resolvedTheme
Theme-->>User: apply resolved theme
Palette->>Palette: close
User->>Hotkeys: press fullscreen hotkey
Hotkeys->>Palette: trigger fullscreen command
Palette->>Tauri: getCurrentWindow().setFullscreen(...)
Tauri-->>User: window fullscreen toggled
Palette->>Palette: close
User->>Palette: select "Toggle Sidebar"
Palette->>Sidebar: dispatch SIDEBAR_TOGGLE_EVENT
Sidebar->>Sidebar: toggleSidebar()
Palette->>Palette: close
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/components/command-palette/command-palette.tsx (2)
86-94: Extract duplicated fullscreen toggle logic.The fullscreen toggle implementation appears twice: in the command's
onSelect(lines 86-94) and inhandleToggleFullscreen(lines 204-212). Consider extracting to a single shared function.♻️ Proposed refactor
+ const handleToggleFullscreen = async () => { + if (!isTauri()) { + return; + } + + const appWindow = getCurrentWindow(); + const isFullscreen = await appWindow.isFullscreen(); + await appWindow.setFullscreen(!isFullscreen); + }; + const commands = useMemo<PaletteCommand[]>( () => [ // ... other commands { id: "toggle-fullscreen", label: "Toggle fullscreen", group: "Window", icon: Maximize, - onSelect: async () => { - if (!isTauri()) { - return; - } - - const appWindow = getCurrentWindow(); - const isFullscreen = await appWindow.isFullscreen(); - await appWindow.setFullscreen(!isFullscreen); - }, + onSelect: handleToggleFullscreen, disabled: !isTauri(), // ... }, ], - [/* deps */], + [/* add handleToggleFullscreen to deps */], ); - - const handleToggleFullscreen = async () => { - // remove duplicate - };Also applies to: 204-212
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/command-palette/command-palette.tsx` around lines 86 - 94, Duplicate fullscreen toggle logic exists in the command's onSelect handler and in handleToggleFullscreen; extract that logic into a single reusable async function (e.g., toggleFullscreen) that checks isTauri(), calls getCurrentWindow(), reads isFullscreen() and calls setFullscreen(!isFullscreen), then replace the bodies of onSelect and handleToggleFullscreen to simply call this new toggleFullscreen function to remove duplication and keep behavior identical.
112-121: Remove redundantlocation.pathnamefrom dependencies.
location.pathnameis only used to computeisSidebarAvailable(line 49), which is already listed in the dependency array. Including both is redundant.♻️ Proposed fix
[ isSidebarAvailable, - location.pathname, openProject, openProjectInSeparateWindow, resolvedTheme, selectedProjectId, toggleThemePreference, ],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/command-palette/command-palette.tsx` around lines 112 - 121, The dependency array for the hook includes a redundant dependency: remove location.pathname from the dependency list and keep isSidebarAvailable (which already derives from location.pathname) to avoid double-triggering; update the array used in the hook inside command-palette.tsx (the one currently listing isSidebarAvailable, location.pathname, openProject, openProjectInSeparateWindow, resolvedTheme, selectedProjectId, toggleThemePreference) so it omits location.pathname but retains isSidebarAvailable and the other handlers/state values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/command-palette/command-palette.tsx`:
- Around line 86-94: Duplicate fullscreen toggle logic exists in the command's
onSelect handler and in handleToggleFullscreen; extract that logic into a single
reusable async function (e.g., toggleFullscreen) that checks isTauri(), calls
getCurrentWindow(), reads isFullscreen() and calls setFullscreen(!isFullscreen),
then replace the bodies of onSelect and handleToggleFullscreen to simply call
this new toggleFullscreen function to remove duplication and keep behavior
identical.
- Around line 112-121: The dependency array for the hook includes a redundant
dependency: remove location.pathname from the dependency list and keep
isSidebarAvailable (which already derives from location.pathname) to avoid
double-triggering; update the array used in the hook inside command-palette.tsx
(the one currently listing isSidebarAvailable, location.pathname, openProject,
openProjectInSeparateWindow, resolvedTheme, selectedProjectId,
toggleThemePreference) so it omits location.pathname but retains
isSidebarAvailable and the other handlers/state values.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bcb275e6-c6cd-4206-bbc2-836e416ae874
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (12)
package.jsonsrc-tauri/capabilities/default.jsonsrc-tauri/capabilities/desktop.jsonsrc/components/command-palette/command-palette.tsxsrc/components/command-palette/index.tssrc/components/ui/command.tsxsrc/components/ui/sidebar.tsxsrc/contexts/app-providers.tsxsrc/contexts/projects-context.tsxsrc/contexts/theme-context.tsxsrc/routes/__root.tsxsrc/routes/projects.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/components/command-palette/command-palette.tsx (1)
165-227: Consider extracting shared hotkey options.The repeated hotkey option objects are mostly identical; extracting shared config would reduce duplication and make future keybinding changes less error-prone.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/command-palette/command-palette.tsx` around lines 165 - 227, Extract the repeated hotkey option object into a shared constant (e.g., hotkeyOptionsBase) and reuse it in each useHotkey call, then extend/override only the differing fields per-hotkey (for example create variants that set enabled: !isOpen, enabled: !isOpen && Boolean(selectedProjectId), and enabled: !isOpen && isTauri()). Update the useHotkey calls (the ones invoking openProject, openProjectInSeparateWindow, toggleThemePreference, toggleFullscreen) to spread hotkeyOptionsBase and then provide the per-call enabled value so behavior (ignoreInputs/preventDefault) remains identical while removing duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/command-palette/command-palette.tsx`:
- Around line 133-140: The runCommand executor currently awaits
command.onSelect() with no error handling; wrap all command and hotkey
invocations (the runCommand function and any hotkey-triggered calls that
currently call command.onSelect or similar handlers) in a single safe executor
that performs try/catch, logs the error via the existing logger, and surfaces a
user-facing toast/error notification; specifically, change runCommand to return
immediately for disabled commands, then call a new safeExecute(async () =>
command.onSelect()) which catches errors and calls processLogger.error(...) and
showToast/errorToast(...), and update any hotkey handlers that directly call
command.onSelect to use safeExecute as well so all async actions have consistent
handling.
---
Nitpick comments:
In `@src/components/command-palette/command-palette.tsx`:
- Around line 165-227: Extract the repeated hotkey option object into a shared
constant (e.g., hotkeyOptionsBase) and reuse it in each useHotkey call, then
extend/override only the differing fields per-hotkey (for example create
variants that set enabled: !isOpen, enabled: !isOpen &&
Boolean(selectedProjectId), and enabled: !isOpen && isTauri()). Update the
useHotkey calls (the ones invoking openProject, openProjectInSeparateWindow,
toggleThemePreference, toggleFullscreen) to spread hotkeyOptionsBase and then
provide the per-call enabled value so behavior (ignoreInputs/preventDefault)
remains identical while removing duplication.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e0c22fd2-3fdf-4109-818e-37e805bbfd55
📒 Files selected for processing (1)
src/components/command-palette/command-palette.tsx
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/command-palette/command-palette.tsx (1)
140-149: Unnecessary dependency inuseMemo.
safeExecuteis included in the dependency array but is not used within thecommandsdefinition. The wrapping happens inrunCommand, not inside thisuseMemo. This causes unnecessary re-computation of commands whensafeExecutereference changes.Proposed fix
[ isSidebarAvailable, openProject, openProjectInSeparateWindow, resolvedTheme, - safeExecute, selectedProjectId, toggleFullscreen, toggleThemePreference, ],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/command-palette/command-palette.tsx` around lines 140 - 149, The useMemo that builds the commands array is including safeExecute in its dependency list even though safeExecute is not referenced inside the commands definition; remove safeExecute from the dependency array so commands only depend on actual values used (isSidebarAvailable, openProject, openProjectInSeparateWindow, resolvedTheme, selectedProjectId, toggleFullscreen, toggleThemePreference). Keep safeExecute referenced where it’s actually used (in runCommand) and ensure tests/usage still work after removing it from the useMemo dependencies.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/command-palette/command-palette.tsx`:
- Around line 140-149: The useMemo that builds the commands array is including
safeExecute in its dependency list even though safeExecute is not referenced
inside the commands definition; remove safeExecute from the dependency array so
commands only depend on actual values used (isSidebarAvailable, openProject,
openProjectInSeparateWindow, resolvedTheme, selectedProjectId, toggleFullscreen,
toggleThemePreference). Keep safeExecute referenced where it’s actually used (in
runCommand) and ensure tests/usage still work after removing it from the useMemo
dependencies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 05d4429f-5e9d-44c9-8081-dccf1ab73256
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
package.jsonsrc/components/command-palette/command-palette.tsxsrc/components/ui/sonner.tsxsrc/lib/logger.tssrc/routes/__root.tsx
✅ Files skipped from review due to trivial changes (2)
- package.json
- src/lib/logger.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/routes/__root.tsx
Summary
cmdkand TanStack Hotkeys/projectsTesting
bun run build./node_modules/.bin/tsc --noEmitSummary by CodeRabbit
New Features
Refactor
Chores