Skip to content

Minor fixes 0731 2 (chat boosted) #1265

Merged
duckduckhero merged 14 commits intomainfrom
minor-fixes-0731-2
Aug 1, 2025
Merged

Minor fixes 0731 2 (chat boosted) #1265
duckduckhero merged 14 commits intomainfrom
minor-fixes-0731-2

Conversation

@duckduckhero
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

📝 Walkthrough

Walkthrough

A chat feature with mention support was integrated into the desktop application's note editor area. This involved adding a chat button to the note header, replacing the chat input's textarea with a rich text editor supporting mentions, updating chat logic to handle mentioned notes and people, and propagating these changes through the chat view and logic layers.

Changes

Cohort / File(s) Change Summary
Note Header Chat Button
apps/desktop/src/components/editor-area/note-header/chips/index.tsx
Added a StartChatButton React component using useRightPanel to toggle the chat panel. Inserted this button into NoteHeaderChips, placing it between existing chips to provide a chat entry point in the note header UI.
Chat Input Rich Editor & Mentions
apps/desktop/src/components/right-panel/components/chat/chat-input.tsx
Refactored ChatInput to use a rich text editor (@hypr/tiptap/editor) with mention support, replacing the textarea. Updated the onSubmit prop to accept mentioned content, added logic to extract mentions, handle mention search, throttle analytics, and synchronize editor state. Enhanced keyboard and click event handling, and updated styling to support the new editor and mentions.
Chat Logic: Mention Context & Message Limits
apps/desktop/src/components/right-panel/hooks/useChatLogic.ts
Extended chat logic to accept and process mentioned notes and people, appending their content to user messages for context. Updated function signatures to propagate mentioned content, increased the free user message limit, and removed a debug log.
Chat View Propagation
apps/desktop/src/components/right-panel/views/chat-view.tsx
Changed the onSubmit prop for ChatInput to forward mentioned content by wrapping handleSubmit in an arrow function, ensuring the new parameter is passed through the view layer.
Localization Metadata Updates
apps/desktop/src/locales/en/messages.po, apps/desktop/src/locales/ko/messages.po
Updated source code reference line numbers for translation entries in English and Korean locale .po files. Marked one usage data message as obsolete. No changes to translation strings or logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NoteHeaderChips
    participant RightPanel (Chat)
    participant ChatInput
    participant useChatLogic

    User->>NoteHeaderChips: Clicks "Chat" button
    NoteHeaderChips->>RightPanel (Chat): togglePanel("chat")
    User->>ChatInput: Types message, adds mentions
    ChatInput->>useChatLogic: onSubmit(message, mentionedContent)
    useChatLogic->>useChatLogic: prepareMessageHistory(..., mentionedContent)
    useChatLogic->>useChatLogic: Append mentioned notes/people content
    useChatLogic-->>ChatInput: Message processed with context
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

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.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b43ffeb and f53b357.

📒 Files selected for processing (2)
  • apps/desktop/src/locales/en/messages.po (8 hunks)
  • apps/desktop/src/locales/ko/messages.po (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/desktop/src/locales/en/messages.po
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: ci (windows, windows-latest)
  • GitHub Check: ci (macos, macos-latest)
🔇 Additional comments (1)
apps/desktop/src/locales/ko/messages.po (1)

17-17: LGTM! Translation metadata synchronized correctly.

The line number updates in source code references are consistent with the source file modifications. All references to src/components/settings/views/general.tsx have been incremented by 3 lines, and one obsolete message has been properly marked. This maintains translation system integrity.

Also applies to: 347-347, 631-631, 661-661, 816-817, 1140-1140, 1272-1272, 1316-1316

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch minor-fixes-0731-2

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
apps/desktop/src/components/right-panel/hooks/useChatLogic.ts (1)

368-372: Remove legacy keyboard handler and rely on ChatInput’s onSubmit

The handleKeyDown in useChatLogic bypasses ChatInput’s mention-extraction and content-reset logic and is no longer needed—Editor already invokes the onSubmit prop when Enter is pressed.

• In apps/desktop/src/components/right-panel/hooks/useChatLogic.ts
– Delete the entire handleKeyDown declaration (lines 368–372)
– Remove handleKeyDown from the returned object.

• In apps/desktop/src/components/right-panel/views/chat-view.tsx
– Stop passing handleKeyDown to <ChatInput … /> (around line 167).

• (Optional) Tidy up the ChatInputProps interface and Editor invocation in
apps/desktop/src/components/right-panel/components/chat/chat-input.tsx by removing the now-unused onKeyDown prop.

Example diff in useChatLogic.ts:

-  const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
-    if (e.key === "Enter" && !e.shiftKey) {
-      e.preventDefault();
-      handleSubmit();
-    }
-  };
 
   return {
     isGenerating,
-    handleKeyDown,
     handleSubmit,
     handleQuickAction,
     handleApplyMarkdown,
   };

And in ChatView.tsx:

-    <ChatInput
-
-      onSubmit={handleSubmit}
-      onKeyDown={handleKeyDown}
-
-    />
+    <ChatInput
+
+      onSubmit={handleSubmit}
+
+    />
🧹 Nitpick comments (3)
apps/desktop/src/components/right-panel/hooks/useChatLogic.ts (1)

137-212: Performance: Sequential await calls in loop

Multiple await calls inside the loop can be slow. Consider parallelizing the data fetching.

-      for (const mention of mentionedContent) {
+      const mentionPromises = mentionedContent.map(async (mention) => {
         try {
           if (mention.type === "note") {
             const sessionData = await dbCommands.getSession({ id: mention.id });
             
             if (sessionData) {
               // ... rest of note processing
-              noteContents.push(`\n\n--- Content from the note"${mention.label}" ---\n${noteContent}`);
+              return `\n\n--- Content from the note "${mention.label}" ---\n${noteContent}`;
             }
           }
           
           if (mention.type === "human") {
             // ... human processing
-              noteContents.push(`\n\n--- Content about the person "${mention.label}" ---\n${humanContent}`);
+              return `\n\n--- Content about the person "${mention.label}" ---\n${humanContent}`;
           }
         } catch (error) {
           console.error(`Error fetching content for "${mention.label}":`, error);
+          return null;
         }
-      }
+      });
+      
+      const results = await Promise.all(mentionPromises);
+      const noteContents = results.filter(content => content !== null);
apps/desktop/src/components/right-panel/views/chat-view.tsx (1)

170-170: Simplify arrow function

The arrow function wrapper is unnecessary since you're just passing through the same arguments.

-        onSubmit={(mentionedContent) => handleSubmit(mentionedContent)}
+        onSubmit={handleSubmit}
apps/desktop/src/components/right-panel/components/chat/chat-input.tsx (1)

262-323: Move inline styles to external CSS file

The large inline style block makes the component harder to maintain. Consider moving these styles to a separate CSS module.

Create a new file chat-input.module.css and import it:

+import styles from './chat-input.module.css';

 return (
   <div className="border border-b-0 border-input mx-4 rounded-t-lg overflow-clip flex flex-col bg-white">
-    {/* Custom styles to disable rich text features */}
-    <style>
-      {`...`}
-    </style>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f312513 and b43ffeb.

📒 Files selected for processing (4)
  • apps/desktop/src/components/editor-area/note-header/chips/index.tsx (2 hunks)
  • apps/desktop/src/components/right-panel/components/chat/chat-input.tsx (5 hunks)
  • apps/desktop/src/components/right-panel/hooks/useChatLogic.ts (5 hunks)
  • apps/desktop/src/components/right-panel/views/chat-view.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,ts,tsx,rs}

⚙️ CodeRabbit Configuration File

**/*.{js,ts,tsx,rs}: 1. No error handling.
2. No unused imports, variables, or functions.
3. For comments, keep it minimal. It should be about "Why", not "What".

Files:

  • apps/desktop/src/components/right-panel/views/chat-view.tsx
  • apps/desktop/src/components/editor-area/note-header/chips/index.tsx
  • apps/desktop/src/components/right-panel/hooks/useChatLogic.ts
  • apps/desktop/src/components/right-panel/components/chat/chat-input.tsx
🔇 Additional comments (5)
apps/desktop/src/components/right-panel/hooks/useChatLogic.ts (1)

187-194: DOM manipulation in potentially non-browser environment

Using document.createElement assumes a browser environment. This could fail in server-side rendering or testing environments.

Consider using a more robust HTML parsing solution or adding environment checks:

-                        const div = document.createElement("div");
-                        div.innerHTML = session.enhanced_memo_html;
-                        briefContent = (div.textContent || div.innerText || "").slice(0, 200) + "...";
+                        // Use a HTML parser library or check for browser environment
+                        if (typeof document !== 'undefined') {
+                          const div = document.createElement("div");
+                          div.innerHTML = session.enhanced_memo_html;
+                          briefContent = (div.textContent || div.innerText || "").slice(0, 200) + "...";
+                        } else {
+                          // Fallback for non-browser environments
+                          briefContent = session.enhanced_memo_html.replace(/<[^>]*>/g, '').slice(0, 200) + "...";
+                        }
apps/desktop/src/components/editor-area/note-header/chips/index.tsx (1)

8-24: Well-implemented chat button component

The StartChatButton component is cleanly implemented with proper event handling and styling.

apps/desktop/src/components/right-panel/components/chat/chat-input.tsx (3)

119-124: DOM manipulation without environment check

The extractPlainText function uses DOM APIs that may not be available in all environments.

   const extractPlainText = useCallback((html: string) => {
+    if (typeof document === 'undefined') {
+      // Fallback for non-browser environments
+      return html.replace(/<[^>]*>/g, '');
+    }
     const div = document.createElement("div");
     div.innerHTML = html;
     return div.textContent || div.innerText || "";
   }, []);

138-181: Add error handling to mention extraction

The extractMentionedContent function should handle potential errors during JSON traversal.

   const extractMentionedContent = useCallback(() => {
+    try {
       if (!editorRef.current?.editor) {
         return [];
       }
 
       const doc = editorRef.current.editor.getJSON();
       // ... rest of the function
       
       return mentions;
+    } catch (error) {
+      console.error('Failed to extract mentions:', error);
+      return [];
+    }
   }, []);

Likely an incorrect or invalid review comment.


79-117: Add error handling for database operations

The handleMentionSearch function lacks error handling for database calls, which could cause the mention search to fail silently.

   const handleMentionSearch = useCallback(async (query: string) => {
+    try {
       const now = Date.now();
       const timeSinceLastEvent = now - lastBacklinkSearchTime.current;
 
       // ... existing code ...
 
       return [...noteResults, ...peopleResults].slice(0, 5);
+    } catch (error) {
+      console.error('Failed to search mentions:', error);
+      return [];
+    }
   }, [userId]);

Likely an incorrect or invalid review comment.

editor.view.dom.removeEventListener("click", handleClick);
};
}
}, [editorRef.current?.editor, onKeyDown, handleSubmit, inputValue]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unstable dependency in useEffect

Including editorRef.current?.editor in the dependency array can cause the effect to run on every render since the editor instance might change.

-  }, [editorRef.current?.editor, onKeyDown, handleSubmit, inputValue]);
+  }, [onKeyDown, handleSubmit, inputValue]);

Instead, check for editor existence inside the effect and use a ref to track if listeners are already attached.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}, [editorRef.current?.editor, onKeyDown, handleSubmit, inputValue]);
}, [onKeyDown, handleSubmit, inputValue]);
🤖 Prompt for AI Agents
In apps/desktop/src/components/right-panel/components/chat/chat-input.tsx at
line 243, remove editorRef.current?.editor from the useEffect dependency array
to prevent the effect from running on every render due to unstable reference
changes. Instead, inside the effect, check if the editor instance exists and use
a separate ref to track whether event listeners have already been attached,
ensuring listeners are added only once.

Comment on lines +128 to +134
if (mentionedContent && mentionedContent.length > 0) {
currentUserMessage +=
"[[From here is an automatically appended content from the mentioned notes & people, not what the user wrote. Use this only as a reference for more context. Your focus should always be the current meeting user is viewing]]"
+ "\n\n";
}

if (mentionedContent && mentionedContent.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate condition check for mentionedContent

The same condition if (mentionedContent && mentionedContent.length > 0) is checked twice. Consider combining these blocks.

-    if (mentionedContent && mentionedContent.length > 0) {
-      currentUserMessage +=
-        "[[From here is an automatically appended content from the mentioned notes & people, not what the user wrote. Use this only as a reference for more context. Your focus should always be the current meeting user is viewing]]"
-        + "\n\n";
-    }
-
-    if (mentionedContent && mentionedContent.length > 0) {
+    if (mentionedContent && mentionedContent.length > 0) {
+      currentUserMessage +=
+        "[[From here is an automatically appended content from the mentioned notes & people, not what the user wrote. Use this only as a reference for more context. Your focus should always be the current meeting user is viewing]]"
+        + "\n\n";
+
       const noteContents: string[] = [];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (mentionedContent && mentionedContent.length > 0) {
currentUserMessage +=
"[[From here is an automatically appended content from the mentioned notes & people, not what the user wrote. Use this only as a reference for more context. Your focus should always be the current meeting user is viewing]]"
+ "\n\n";
}
if (mentionedContent && mentionedContent.length > 0) {
if (mentionedContent && mentionedContent.length > 0) {
currentUserMessage +=
"[[From here is an automatically appended content from the mentioned notes & people, not what the user wrote. Use this only as a reference for more context. Your focus should always be the current meeting user is viewing]]"
+ "\n\n";
const noteContents: string[] = [];
🤖 Prompt for AI Agents
In apps/desktop/src/components/right-panel/hooks/useChatLogic.ts around lines
128 to 134, the condition checking if mentionedContent exists and has length
greater than zero is duplicated. Combine these two if blocks into one to avoid
redundant checks by merging their contents under a single if statement that
checks mentionedContent and its length once.

continue;
}

noteContents.push(`\n\n--- Content from the note"${mention.label}" ---\n${noteContent}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing space in string concatenation

Missing space between "note" and the quote character in the string template.

-              noteContents.push(`\n\n--- Content from the note"${mention.label}" ---\n${noteContent}`);
+              noteContents.push(`\n\n--- Content from the note "${mention.label}" ---\n${noteContent}`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
noteContents.push(`\n\n--- Content from the note"${mention.label}" ---\n${noteContent}`);
noteContents.push(`\n\n--- Content from the note "${mention.label}" ---\n${noteContent}`);
🤖 Prompt for AI Agents
In apps/desktop/src/components/right-panel/hooks/useChatLogic.ts at line 153,
there is a missing space between the word "note" and the quote character in the
string template. Fix this by adding a space after "note" so the string reads
`note "${mention.label}"` instead of `note"${mention.label}"`.

Comment on lines +238 to +245
if (messages.length >= 14 && !getLicense.data?.valid) {
if (userId) {
await analyticsCommands.event({
event: "pro_license_required_chat",
distinct_id: userId,
});
}
await message("2 messages are allowed per conversation for free users.", {
await message("7 messages are allowed per conversation for free users.", {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent message limit logic

The code checks for 14 messages but displays "7 messages" to the user. This seems inconsistent - if you're counting individual messages (user + assistant), then 14 messages would be 7 conversation turns.

Either update the check or the message to be consistent:

-    if (messages.length >= 14 && !getLicense.data?.valid) {
+    if (messages.length >= 14 && !getLicense.data?.valid) {
       // ... 
-      await message("7 messages are allowed per conversation for free users.", {
+      await message("7 conversation turns (14 messages) are allowed per conversation for free users.", {
🤖 Prompt for AI Agents
In apps/desktop/src/components/right-panel/hooks/useChatLogic.ts around lines
238 to 245, the code checks if messages.length is at least 14 but the user
message states "7 messages are allowed," causing inconsistency. Fix this by
either changing the condition to check for 7 messages or updating the displayed
message to reflect 14 messages, ensuring the limit logic and user notification
match.

@duckduckhero duckduckhero merged commit bdb298f into main Aug 1, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 5, 2025
This was referenced Oct 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant