Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions apps/mail/components/mail/mail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,34 +678,18 @@ function CategoryDropdown({ isMultiSelectMode }: CategoryDropdownProps) {
const folder = params?.folder ?? 'inbox';
const [isOpen, setIsOpen] = useState(false);

categorySettings.forEach((category, index) => {
if (index < 9) {
const keyNumber = (index + 1).toString();
useHotkeys(
keyNumber,
() => {
const isCurrentlyActive = labels.includes(category.searchValue);

if (isCurrentlyActive) {
setLabels(labels.filter((label) => label !== category.searchValue));
} else {
setLabels([...labels, category.searchValue]);
}
},
{
scopes: ['mail-list'],
preventDefault: true,
enableOnFormTags: false,
},
[category.searchValue, labels, setLabels], // Dependencies
);
}
});

useHotkeys(
'0',
() => {
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>

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];

if (!category) return;
const isCurrentlyActive = labels.includes(category.searchValue);

if (isCurrentlyActive) {
setLabels(labels.filter((label) => label !== category.searchValue));
} else {
setLabels([...labels, category.searchValue]);
}
},
{
scopes: ['mail-list'],
Expand Down