Skip to content

Conversation

@yyhhyyyyyy
Copy link
Collaborator

@yyhhyyyyyy yyhhyyyyyy commented Aug 27, 2025

enhance image file display with context-aware thumbnails
CleanShot 2025-08-27 at 14 08 58@2x
CleanShot 2025-08-27 at 14 09 06@2x

Summary by CodeRabbit

  • New Features
    • Pasted images now include and display thumbnails in the chat.
    • Image attachments in messages show a larger preview with filename and type for quicker recognition.
    • Attachments render contextually: compact layout in the input area, richer preview in messages.
    • Consistent delete overlay on attachments for easy removal.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

Walkthrough

Adds a context prop to FileItem for layout control, introduces image-specific rendering in message context, and updates ChatInput to pass context='input'. Paste handling now includes a thumbnail field on image MessageFile objects sourced from compressed base64.

Changes

Cohort / File(s) Summary of Changes
Renderer components
src/renderer/src/components/ChatInput.vue, src/renderer/src/components/FileItem.vue
ChatInput passes context='input' to FileItem; FileItem adds context prop (`'input'
Shared types
@shared/chat
Extends MessageFile interface with thumbnail: string; paste handler in ChatInput populates thumbnail from imageInfo.compressedBase64.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CI as ChatInput.vue
  participant FI as FileItem.vue
  participant Types as @shared/chat (MessageFile)

  U->>CI: Paste image
  CI->>CI: Extract imageInfo (compressedBase64)
  CI->>Types: Create MessageFile { thumbnail, ... }
  CI->>FI: Render FileItem context='input' with file data

  Note over FI: New prop 'context' controls layout<br/>Image-specific UI only when context == 'message'

  U->>CI: Send message
  CI->>FI: Render in message list context='message'
  alt Image file with thumbnail
    FI->>FI: isImageFile == true
    FI-->U: Show vertical thumbnail card + delete action
  else Non-image or no thumbnail
    FI-->U: Show horizontal item layout + delete action
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A thumbnail hops into the chat, so bright,
I wiggle my ears—the layout feels right.
Input or message, I know where to be,
Context-aware, like a bunny is free.
Paste, compress, and swiftly display—
Thump goes my paw: ship it today! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/enhance-image-thumbnail-display

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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/renderer/src/components/FileItem.vue (1)

63-65: Use i18n for user-visible “tokens” label

Renderer must not hardcode user-facing strings. Inject vue-i18n and use a key, e.g., fileItem.tokens.

@@
-        <TooltipContent>
-          <p>{{ tokens }} tokens</p>
-        </TooltipContent>
+        <TooltipContent>
+          <p>{{ t('fileItem.tokens', { count: tokens }) }}</p>
+        </TooltipContent>
-import { computed } from 'vue'
+import { computed } from 'vue'
+import { useI18n } from 'vue-i18n'
@@
-defineEmits<{
+const { t } = useI18n()
+
+defineEmits<{

Follow-up: add fileItem.tokens to locale files (e.g., "fileItem.tokens": "{count} tokens").

Also applies to: 72-72, 92-92

src/renderer/src/components/ChatInput.vue (1)

524-524: Unify logs to English per repo guideline

Several console messages are in Chinese; convert to English.

-        console.error('文件处理失败:', error)
+        console.error('File processing failed:', error)
@@
-        console.error('文件准备失败:', error)
+        console.error('File preparation failed:', error)
@@
-              console.error('读取资源失败:', error)
+              console.error('Failed to read resource:', error)
@@
-        console.error('文件准备失败:', error)
+        console.error('File preparation failed:', error)
@@
-        console.warn('恢复焦点时出错:', error)
+        console.warn('Error restoring focus:', error)

Also applies to: 549-549, 621-621, 925-925, 1195-1195

🧹 Nitpick comments (4)
src/renderer/src/components/FileItem.vue (2)

12-12: Add alt text + lazy/async decoding and fixed dimensions to thumbnails

Improves a11y, CLS, and performance; aligns with our image optimization learnings.

-            <img :src="thumbnail" class="w-20 h-20 rounded-md border object-cover" />
+            <img
+              :src="thumbnail"
+              :alt="fileName"
+              loading="lazy"
+              decoding="async"
+              width="80"
+              height="80"
+              class="w-20 h-20 rounded-md border object-cover"
+            />
-            <img v-if="thumbnail" :src="thumbnail" class="w-8 h-8 rounded-md border" />
+            <img
+              v-if="thumbnail"
+              :src="thumbnail"
+              :alt="fileName"
+              loading="lazy"
+              decoding="async"
+              width="32"
+              height="32"
+              class="w-8 h-8 rounded-md border"
+            />

Also applies to: 37-37


6-6: Translate inline comments to English

Repo guideline: use English for all comments. Please convert the template comments.

-          <!-- 图片文件在消息中使用特殊布局 -->
+          <!-- Use special layout for image files inside messages -->
@@
-          <!-- 非图片文件或输入框中的图片使用原有布局 -->
+          <!-- Use the original layout for non-image files or images inside the input area -->

Also applies to: 31-31

src/renderer/src/components/ChatInput.vue (2)

35-35: Use literal binding for static prop

No need for v-bind when passing a static string.

-              :context="'input'"
+              context="input"

972-1005: Detach DOM/window listeners on unmount to avoid leaks

Extract handlers to named functions, add/remove them in mounted/unmounted.

@@
-onMounted(() => {
+const handleContextMenuAskAI = (e: any) => {
+  inputText.value = e.detail
+  editor.commands.setContent(e.detail)
+  editor.commands.focus()
+}
+const handleVisibilityChange = () => {
+  if (!document.hidden) {
+    setTimeout(() => {
+      restoreFocus()
+    }, 100)
+  }
+}
+
+onMounted(() => {
@@
-  window.addEventListener('context-menu-ask-ai', (e: any) => {
-    inputText.value = e.detail
-    editor.commands.setContent(e.detail)
-    editor.commands.focus()
-  })
+  window.addEventListener('context-menu-ask-ai', handleContextMenuAskAI)
@@
-  document.addEventListener('visibilitychange', () => {
-    if (!document.hidden) {
-      setTimeout(() => {
-        restoreFocus()
-      }, 100)
-    }
-  })
+  document.addEventListener('visibilitychange', handleVisibilityChange)
@@
 onUnmounted(() => {
@@
-  window.electron.ipcRenderer.removeListener('rate-limit:config-updated', handleRateLimitEvent)
+  window.electron.ipcRenderer.removeListener('rate-limit:config-updated', handleRateLimitEvent)
   window.electron.ipcRenderer.removeListener('rate-limit:request-executed', handleRateLimitEvent)
   window.electron.ipcRenderer.removeListener('rate-limit:request-queued', handleRateLimitEvent)
+  window.removeEventListener('context-menu-ask-ai', handleContextMenuAskAI)
+  document.removeEventListener('visibilitychange', handleVisibilityChange)
 })

If adding new top-level consts outside the shown ranges is preferable, place the two handler declarations just above onMounted.

Also applies to: 1007-1014

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3643fb2 and d44338d.

📒 Files selected for processing (2)
  • src/renderer/src/components/ChatInput.vue (2 hunks)
  • src/renderer/src/components/FileItem.vue (4 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
src/renderer/src/**/*

📄 CodeRabbit inference engine (.cursor/rules/i18n.mdc)

src/renderer/src/**/*: All user-facing strings must use i18n keys (avoid hardcoded user-visible text in code)
Use the 'vue-i18n' framework for all internationalization in the renderer
Ensure all user-visible text in the renderer uses the translation system

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)

src/renderer/src/**/*.{vue,ts,tsx,js,jsx}: Use the Composition API for better code organization and reusability
Implement proper state management with Pinia
Utilize Vue Router for navigation and route management
Leverage Vue's built-in reactivity system for efficient data handling

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/src/**/*.vue

📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)

Use scoped styles to prevent CSS conflicts between components

src/renderer/src/**/*.vue: Follow existing component patterns when creating new UI components
Ensure responsive design with Tailwind CSS for new UI components
Add proper error handling and loading states to UI components

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/**/*.{vue,ts}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/**/*.{ts,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

src/renderer/**/*.{ts,vue}: Use Pinia for frontend state management
From renderer to main, call presenters via the usePresenter.ts composable

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for all logs and comments

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/**/*.vue

📄 CodeRabbit inference engine (CLAUDE.md)

src/renderer/**/*.vue: Use Vue 3 Composition API for all components
Use Tailwind CSS with scoped styles for component styling

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
src/renderer/src/**

📄 CodeRabbit inference engine (CLAUDE.md)

Organize UI components by feature under src/renderer/src/

Files:

  • src/renderer/src/components/FileItem.vue
  • src/renderer/src/components/ChatInput.vue
🧠 Learnings (3)
📚 Learning: 2025-07-23T00:45:57.322Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-07-23T00:45:57.322Z
Learning: Applies to src/renderer/**/*.{vue} : Use Iconify/Vue for icon implementation.

Applied to files:

  • src/renderer/src/components/FileItem.vue
📚 Learning: 2025-07-23T00:45:57.322Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-07-23T00:45:57.322Z
Learning: Applies to src/renderer/**/*.{vue} : Optimize images: use WebP format, include size data, implement lazy loading.

Applied to files:

  • src/renderer/src/components/FileItem.vue
📚 Learning: 2025-07-23T00:45:57.322Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/vue-shadcn.mdc:0-0
Timestamp: 2025-07-23T00:45:57.322Z
Learning: Applies to src/renderer/**/*.{vue} : Import Icon component from Iconify/Vue.

Applied to files:

  • src/renderer/src/components/FileItem.vue
⏰ 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). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (3)
src/renderer/src/components/FileItem.vue (2)

101-103: Image type detection is correct and concise

Using startsWith('image/') is appropriate here.


84-89: All FileItem instances correctly handle the new context prop

  • In MessageItemUser.vue, the context prop is omitted, so it safely defaults to 'message'.
  • In ChatInput.vue, the context prop is explicitly set to 'input'.

No additional call sites require updates.

src/renderer/src/components/ChatInput.vue (1)

506-508: Thumbnail wiring verified—no changes needed

I’ve confirmed that:

  • The MessageFile type in src/shared/chat.d.ts declares thumbnail?: string, allowing both defined and undefined values.
  • Both prepareFile and prepareDirectory in src/main/presenter/filePresenter/FilePresenter.ts always include a thumbnail field (defaulting to '' or the adapter’s result), covering drag-and-drop, file picker, and paste paths.
  • The UI components (ChatInput.vue, FileItem.vue, etc.) already handle missing or empty thumbnails gracefully.

All ingestion paths align correctly.

@zerob13 zerob13 merged commit 565e38f into dev Aug 27, 2025
2 checks passed
@zerob13 zerob13 deleted the feat/enhance-image-thumbnail-display branch January 6, 2026 12:16
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.

3 participants