Skip to content

Template Selector Merge #1089

Merged
duckduckhero merged 7 commits intomainfrom
template-selector-0706
Jul 6, 2025
Merged

Template Selector Merge #1089
duckduckhero merged 7 commits intomainfrom
template-selector-0706

Conversation

@duckduckhero
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

📝 Walkthrough

Walkthrough

Enhancement templates can now be selected and applied to notes via a popover menu integrated with the enhance button in the editor area. The UI, state management, and enhancement workflow were updated to support template selection, analytics tracking, and conditional progress display, with additional logic for restoring original template settings after enhancement.

Changes

File(s) Change Summary
apps/desktop/src/components/editor-area/floating-button.tsx Enhanced FloatingButton with a template selection popover, new props for template handling, analytics tracking, and UI logic.
apps/desktop/src/components/editor-area/index.tsx Integrated React Query for templates/config, added template selection callback, updated enhancement workflow, and state management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FloatingButton
    participant EditorArea
    participant Database

    User->>FloatingButton: Hover/click Enhance button
    FloatingButton->>User: Show template popover
    User->>FloatingButton: Select template
    FloatingButton->>EditorArea: handleEnhanceWithTemplate(templateId)
    EditorArea->>Database: Update config with templateId
    Database-->>EditorArea: Confirm config update
    EditorArea->>EditorArea: Trigger enhancement mutation
    EditorArea->>Database: Enhance note with selected template
    Database-->>EditorArea: Return enhanced note
    EditorArea->>Database: Restore original templateId (if needed)
    EditorArea-->>FloatingButton: Update UI/progress
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@duckduckhero duckduckhero changed the title Template selector 0706 Template Selector Merge Jul 6, 2025
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: 1

🧹 Nitpick comments (1)
apps/desktop/src/components/editor-area/floating-button.tsx (1)

171-181: Add user-facing error feedback.

The error is only logged to console without informing the user that the settings window failed to open.

   const handleAddTemplate = async () => {
     setShowTemplatePopover(false);
     try {
       // Open settings window
       await windowsCommands.windowShow({ type: "settings" });
       // Navigate to templates tab
       await windowsCommands.windowNavigate({ type: "settings" }, "/app/settings?tab=templates");
     } catch (error) {
       console.error("Failed to open settings/templates:", error);
+      toast({
+        title: "Unable to open settings",
+        content: "Please try again or open settings manually.",
+        variant: "destructive",
+      });
     }
   };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 88d39a9 and 7ba2a86.

📒 Files selected for processing (2)
  • apps/desktop/src/components/editor-area/floating-button.tsx (7 hunks)
  • apps/desktop/src/components/editor-area/index.tsx (9 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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".

**/*.{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".

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • apps/desktop/src/components/editor-area/index.tsx
  • apps/desktop/src/components/editor-area/floating-button.tsx
🪛 Biome (1.9.4)
apps/desktop/src/components/editor-area/index.tsx

[error] 584-584: Unexpected control character in a regular expression.

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)


[error] 584-584: Unexpected control character in a regular expression.

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: ci (windows, windows-latest)
  • GitHub Check: ci (macos, macos-latest)
🔇 Additional comments (1)
apps/desktop/src/components/editor-area/index.tsx (1)

584-584: Control character removal is correctly implemented.

The regex pattern /[\x00-\x1F\x7F]/g is intentionally matching and removing control characters from the title. This is the correct approach for sanitizing user input and preventing potential display issues.

Comment on lines +148 to +181
const handleEnhanceWithTemplate = useCallback(async (templateId: string) => {
if (configQuery.data) {
const currentTemplateId = configQuery.data.general?.selected_template_id || null;
setOriginalTemplateId(currentTemplateId);
setNeedsRestoration(true);

const targetTemplateId = templateId === "auto" ? null : templateId;

const updatedConfig = {
...configQuery.data,
general: {
...configQuery.data.general,
selected_template_id: targetTemplateId,
},
};

try {
await setConfigMutation.mutateAsync(updatedConfig);

await new Promise(resolve => setTimeout(resolve, 200));

const verifyConfig = await dbCommands.getConfig();

if (verifyConfig.general?.selected_template_id !== targetTemplateId) {
setOriginalTemplateId(null);
setNeedsRestoration(false);
return;
}
} catch (error) {
setOriginalTemplateId(null);
setNeedsRestoration(false);
return;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving error handling and removing the fragile timeout.

The handleEnhanceWithTemplate function has a few concerns:

  1. The 200ms timeout (line 167) appears to be a workaround for ensuring the config is saved. This is fragile and could fail under different conditions.
  2. Error handling only logs to console without informing the user of failures.

Consider this more robust approach:

-      try {
-        await setConfigMutation.mutateAsync(updatedConfig);
-
-        await new Promise(resolve => setTimeout(resolve, 200));
-
-        const verifyConfig = await dbCommands.getConfig();
-
-        if (verifyConfig.general?.selected_template_id !== targetTemplateId) {
-          setOriginalTemplateId(null);
-          setNeedsRestoration(false);
-          return;
-        }
-      } catch (error) {
-        setOriginalTemplateId(null);
-        setNeedsRestoration(false);
-        return;
-      }
+      try {
+        await setConfigMutation.mutateAsync(updatedConfig);
+        
+        // Wait for the query to be invalidated and refetched
+        await queryClient.refetchQueries({ queryKey: ["config", "general"] });
+        
+        const verifyConfig = await dbCommands.getConfig();
+        
+        if (verifyConfig.general?.selected_template_id !== targetTemplateId) {
+          throw new Error("Failed to update template configuration");
+        }
+      } catch (error) {
+        console.error("Failed to update template:", error);
+        setOriginalTemplateId(null);
+        setNeedsRestoration(false);
+        
+        // Inform the user about the failure
+        toast({
+          title: "Template selection failed",
+          content: "Unable to apply the selected template. Please try again.",
+          variant: "destructive",
+        });
+        return;
+      }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/desktop/src/components/editor-area/index.tsx around lines 148 to 181,
the function handleEnhanceWithTemplate uses a fixed 200ms timeout to wait for
config saving, which is unreliable, and error handling only resets state without
user notification. Replace the timeout with a proper confirmation mechanism that
ensures the config is saved before proceeding, such as awaiting a successful
response or event. Enhance error handling by notifying the user of failures
through UI feedback instead of just resetting state silently.

@duckduckhero duckduckhero merged commit 1f944f3 into main Jul 6, 2025
5 checks passed
@duckduckhero duckduckhero deleted the template-selector-0706 branch July 6, 2025 08:10
@coderabbitai coderabbitai bot mentioned this pull request Sep 1, 2025
@coderabbitai coderabbitai bot mentioned this pull request Sep 10, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 3, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 23, 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

Comments