Skip to content

Comments

fix: hotkeys for categories#1938

Merged
ahmetskilinc merged 1 commit intostagingfrom
08-06-fix_hotkeys_for_categories
Aug 6, 2025
Merged

fix: hotkeys for categories#1938
ahmetskilinc merged 1 commit intostagingfrom
08-06-fix_hotkeys_for_categories

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented Aug 5, 2025

The new implementation:

  • Uses a single useHotkeys call with an array of key combinations
  • Determines the appropriate category based on the pressed key
  • Handles toggling labels in a more centralized way

Summary by CodeRabbit

  • Refactor
    • Simplified hotkey handling for category selection by consolidating multiple hotkey registrations into a single listener.
    • The '0' key now toggles the 10th category instead of clearing all selections.

@jazzberry-ai
Copy link

jazzberry-ai bot commented Aug 5, 2025

Bug Report

Name Severity Example test case Description
Out-of-bounds access for '0' key Critical Press '0' when there are fewer than 10 categories defined. When the '0' key is pressed, the code attempts to access categorySettings[9], regardless of the actual size of the categorySettings array. If the array has fewer than 10 elements, this results in an out-of-bounds error.
Out-of-bounds access for any number key when categorySettings is empty Critical Press any number key when there are no categories defined. When any number key is pressed and the categorySettings array is empty, the code will try to access categorySettings[number - 1] which results in an out-of-bounds error.

Comments? Email us.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The hotkey handling for category selection in the mail component was refactored. Instead of registering separate hotkeys for each number key, a single useHotkeys call now manages keys '1' through '9' and '0', mapping them to category actions in a unified callback. The special case for clearing all labels with '0' was removed.

Changes

Cohort / File(s) Change Summary
Mail Hotkey Refactor
apps/mail/components/mail/mail.tsx
Consolidated multiple hotkey registrations into a single useHotkeys call for keys '1'-'9' and '0'; removed '0' as a clear-all shortcut and unified category mapping logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MailComponent
    participant useHotkeys

    User->>MailComponent: Presses key '1'-'9' or '0'
    MailComponent->>useHotkeys: Receives key event
    useHotkeys->>MailComponent: Calls unified callback with key info
    MailComponent->>MailComponent: Maps key to category index
    MailComponent->>MailComponent: Toggles category label selection
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

Rocketing through code at the speed of light,
Hotkeys unified, the logic’s tight.
No more loops, just streamlined flow,
Categories toggled with a single go.
Simplicity’s power, efficiency’s might—
This refactor’s a Falcon in flight. 🚀

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 085c451 and 5e7572b.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 08-06-fix_hotkeys_for_categories

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review August 5, 2025 23:59
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai coderabbitai bot requested a review from MrgSub August 6, 2025 00:00
@coderabbitai coderabbitai bot added the design Improvements & changes to design & UX label Aug 6, 2025
@ahmetskilinc ahmetskilinc force-pushed the 08-06-fix_hotkeys_for_categories branch from 085c451 to 5e7572b Compare August 6, 2025 00:02
@jazzberry-ai
Copy link

jazzberry-ai bot commented Aug 6, 2025

Bug Report

Name Severity Example test case Description
Missing '0' Key Handling High Pressing '0' should clear all category labels. The patch removed the specific handler for the '0' key, which clears all selected category labels. This functionality has been reintroduced.
Incorrect Category Mapping/Out-of-Bounds Access High Pressing a number key greater than the number of categories should not cause an error. The patch used Number(key.key) - 1 to map hotkeys to categories without checking if the resulting index was within the bounds of the categorySettings array. This could lead to errors. A check has been added to ensure the index is valid before accessing the array.

Comments? Email us.

Copy link
Contributor Author

ahmetskilinc commented Aug 6, 2025

Merge activity

  • Aug 6, 12:02 AM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 6, 12:03 AM UTC: @ahmetskilinc merged this pull request with Graphite.

@ahmetskilinc ahmetskilinc merged commit aaf3199 into staging Aug 6, 2025
6 of 7 checks passed
@ahmetskilinc ahmetskilinc deleted the 08-06-fix_hotkeys_for_categories branch August 6, 2025 00:03
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

2 issues found across 1 file • Review in cubic

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

setLabels([]);
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
(key) => {
const category = categorySettings[Number(key.key) - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‘0’ key does not map to the 10th category; index calculation yields ‑1 so no category is selected.

Prompt for AI agents
Address the following comment on apps/mail/components/mail/mail.tsx at line 684:

<comment>‘0’ key does not map to the 10th category; index calculation yields ‑1 so no category is selected.</comment>

<file context>
@@ -678,34 +678,18 @@ function CategoryDropdown({ isMultiSelectMode }: CategoryDropdownProps) {
   const folder = params?.folder ?? &#39;inbox&#39;;
   const [isOpen, setIsOpen] = useState(false);
 
-  categorySettings.forEach((category, index) =&gt; {
-    if (index &lt; 9) {
-      const keyNumber = (index + 1).toString();
-      useHotkeys(
-        keyNumber,
-        () =&gt; {
</file context>
Suggested change
const category = categorySettings[Number(key.key) - 1];
const category = categorySettings[key.key === '0' ? 9 : Number(key.key) - 1];

() => {
setLabels([]);
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
(key) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule violated: Detect React performance bottlenecks and rule breaking

Inline anonymous function passed to useHotkeys violates the rule prohibiting inline functions in React hooks and can lead to avoidable re-registrations of the hotkey listeners.

Prompt for AI agents
Address the following comment on apps/mail/components/mail/mail.tsx at line 683:

<comment>Inline anonymous function passed to useHotkeys violates the rule prohibiting inline functions in React hooks and can lead to avoidable re-registrations of the hotkey listeners.</comment>

<file context>
@@ -678,34 +678,18 @@ function CategoryDropdown({ isMultiSelectMode }: CategoryDropdownProps) {
   const folder = params?.folder ?? &#39;inbox&#39;;
   const [isOpen, setIsOpen] = useState(false);
 
-  categorySettings.forEach((category, index) =&gt; {
-    if (index &lt; 9) {
-      const keyNumber = (index + 1).toString();
-      useHotkeys(
-        keyNumber,
-        () =&gt; {
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

design Improvements & changes to design & UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant