Skip to content

Update ChatBar.tsx to allow for copy/paste and drag/drop file uploads #7153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pinkhoodie
Copy link
Contributor

@pinkhoodie pinkhoodie commented May 24, 2025


PR-Codex overview

This PR focuses on enhancing the ChatBar component by adding image upload functionality through drag-and-drop and clipboard paste events, improving user experience when sharing images.

Detailed summary

  • Added onDrop event handler to handle image uploads via drag-and-drop.
  • Implemented onDragOver event to prevent default behavior during dragging.
  • Included onPaste event to handle image uploads from clipboard.
  • Minor syntax adjustments for consistency in className usage.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added support for image uploads via drag-and-drop and clipboard paste in the chat bar.
  • Bug Fixes

    • Fixed a minor issue with trailing commas in image upload handling.

@pinkhoodie pinkhoodie requested review from a team as code owners May 24, 2025 00:13
Copy link

changeset-bot bot commented May 24, 2025

⚠️ No Changeset found

Latest commit: 3bdc344

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented May 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 24, 2025 0:18am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) May 24, 2025 0:18am
login ⬜️ Skipped (Inspect) May 24, 2025 0:18am
thirdweb_playground ⬜️ Skipped (Inspect) May 24, 2025 0:18am
wallet-ui ⬜️ Skipped (Inspect) May 24, 2025 0:18am

Copy link
Contributor

graphite-app bot commented May 24, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link

coderabbitai bot commented May 24, 2025

Walkthrough

The ChatBar component now supports image uploads via drag-and-drop and clipboard paste. Event handlers for drag-and-drop and paste events have been added, enabling users to upload images by dragging them into the chat bar or pasting them into the textarea. Minor formatting improvements were also made.

Changes

File(s) Change Summary
.../ChatBar.tsx Added drag-and-drop and paste event handlers for image uploads; updated formatting and minor cleanup.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBar
    participant ImageUploadHandler

    User->>ChatBar: Drag-and-drop image or paste image
    ChatBar->>ImageUploadHandler: handleImageUpload(files)
    ImageUploadHandler-->>ChatBar: Upload result
    ChatBar-->>User: Image appears in chat
Loading

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @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.

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.

@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label May 24, 2025
Copy link

@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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5277edd and 3bdc344.

📒 Files selected for processing (1)
  • apps/dashboard/src/app/nebula-app/(app)/components/ChatBar.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/dashboard/src/app/nebula-app/(app)/components/ChatBar.tsx (4)

113-113: Good formatting improvement.

Removing the trailing comma after the function call improves code consistency.


130-130: Good formatting improvement.

Removing the trailing comma improves code consistency.


284-284: Good formatting improvement.

Removing the trailing comma improves code consistency.


561-561: Good formatting improvement.

Removing the trailing comma improves code consistency.

Comment on lines +132 to +138
onDrop={(e) => {
e.preventDefault();
if (!props.allowImageUpload) return;
const files = Array.from(e.dataTransfer.files);
if (files.length > 0) handleImageUpload(files);
}}
onDragOver={(e) => e.preventDefault()}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing file validation and improve UX for drag-and-drop.

The drag-and-drop implementation bypasses important validation logic present in the ImageUploadButton component. This could lead to inconsistent behavior and poor user experience.

Apply this diff to add missing validation:

        onDrop={(e) => {
          e.preventDefault();
          if (!props.allowImageUpload) return;
          const files = Array.from(e.dataTransfer.files);
-         if (files.length > 0) handleImageUpload(files);
+         if (files.length > 0) {
+           // Validate file count
+           const totalFiles = files.length + images.length;
+           if (totalFiles > maxAllowedImagesPerMessage) {
+             toast.error(
+               `You can only upload up to ${maxAllowedImagesPerMessage} images at a time`,
+               { position: "top-right" }
+             );
+             return;
+           }
+           
+           // Validate file types and sizes
+           const validFiles: File[] = [];
+           for (const file of files) {
+             if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) {
+               toast.error(`Unsupported file type: ${file.type}`, {
+                 description: `File: ${file.name}`,
+                 position: "top-right",
+               });
+               continue;
+             }
+             if (file.size <= 5 * 1024 * 1024) {
+               validFiles.push(file);
+             } else {
+               toast.error("Image is larger than 5MB", {
+                 description: `File: ${file.name}`,
+                 position: "top-right",
+               });
+             }
+           }
+           
+           if (validFiles.length > 0) {
+             handleImageUpload(validFiles);
+           }
+         }
        }}

Additionally, consider adding visual feedback for drag operations and accessibility attributes.

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

🤖 Prompt for AI Agents
In apps/dashboard/src/app/nebula-app/(app)/components/ChatBar.tsx around lines
132 to 138, the onDrop handler lacks file validation consistent with
ImageUploadButton, risking inconsistent behavior. Update the onDrop function to
include the same file type and size validations as ImageUploadButton before
calling handleImageUpload. Also, enhance UX by adding visual feedback during
drag operations (e.g., changing styles on dragOver and dragEnter) and include
appropriate accessibility attributes like aria-dropeffect to improve usability.

Comment on lines +156 to +163
onPaste={(e) => {
if (!props.allowImageUpload) return;
const files = Array.from(e.clipboardData.files);
if (files.length > 0) {
e.preventDefault();
handleImageUpload(files);
}
}}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing file validation for paste functionality.

The paste implementation bypasses the same validation logic as the drag-and-drop handler, creating inconsistent behavior between upload methods.

Apply this diff to add missing validation:

              onPaste={(e) => {
                if (!props.allowImageUpload) return;
                const files = Array.from(e.clipboardData.files);
                if (files.length > 0) {
                  e.preventDefault();
-                 handleImageUpload(files);
+                 // Validate file count
+                 const totalFiles = files.length + images.length;
+                 if (totalFiles > maxAllowedImagesPerMessage) {
+                   toast.error(
+                     `You can only upload up to ${maxAllowedImagesPerMessage} images at a time`,
+                     { position: "top-right" }
+                   );
+                   return;
+                 }
+                 
+                 // Validate file types and sizes
+                 const validFiles: File[] = [];
+                 for (const file of files) {
+                   if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) {
+                     toast.error(`Unsupported file type: ${file.type}`, {
+                       description: `File: ${file.name}`,
+                       position: "top-right",
+                     });
+                     continue;
+                   }
+                   if (file.size <= 5 * 1024 * 1024) {
+                     validFiles.push(file);
+                   } else {
+                     toast.error("Image is larger than 5MB", {
+                       description: `File: ${file.name}`,
+                       position: "top-right",
+                     });
+                   }
+                 }
+                 
+                 if (validFiles.length > 0) {
+                   handleImageUpload(validFiles);
+                 }
                }
              }}
📝 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
onPaste={(e) => {
if (!props.allowImageUpload) return;
const files = Array.from(e.clipboardData.files);
if (files.length > 0) {
e.preventDefault();
handleImageUpload(files);
}
}}
onPaste={(e) => {
if (!props.allowImageUpload) return;
const files = Array.from(e.clipboardData.files);
if (files.length > 0) {
e.preventDefault();
// Validate file count
const totalFiles = files.length + images.length;
if (totalFiles > maxAllowedImagesPerMessage) {
toast.error(
`You can only upload up to ${maxAllowedImagesPerMessage} images at a time`,
{ position: "top-right" }
);
return;
}
// Validate file types and sizes
const validFiles: File[] = [];
for (const file of files) {
if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) {
toast.error(`Unsupported file type: ${file.type}`, {
description: `File: ${file.name}`,
position: "top-right",
});
continue;
}
if (file.size <= 5 * 1024 * 1024) {
validFiles.push(file);
} else {
toast.error("Image is larger than 5MB", {
description: `File: ${file.name}`,
position: "top-right",
});
}
}
if (validFiles.length > 0) {
handleImageUpload(validFiles);
}
}
}}
🤖 Prompt for AI Agents
In apps/dashboard/src/app/nebula-app/(app)/components/ChatBar.tsx around lines
156 to 163, the onPaste handler lacks the file validation present in the
drag-and-drop handler, causing inconsistent behavior. Update the onPaste
function to include the same file validation logic before calling
handleImageUpload, ensuring only valid files are processed. This will align the
paste functionality with the drag-and-drop upload behavior.

Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.70%. Comparing base (3489ece) to head (3bdc344).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7153      +/-   ##
==========================================
+ Coverage   55.68%   55.70%   +0.01%     
==========================================
  Files         904      904              
  Lines       58324    58340      +16     
  Branches     4113     4115       +2     
==========================================
+ Hits        32476    32496      +20     
+ Misses      25743    25739       -4     
  Partials      105      105              
Flag Coverage Δ
packages 55.70% <ø> (+0.01%) ⬆️

see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 61.75 KB (0%) 1.3 s (0%) 397 ms (+54.14% 🔺) 1.7 s
thirdweb (cjs) 344.4 KB (0%) 6.9 s (0%) 2 s (+2.54% 🔺) 8.9 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 89 ms (+510.13% 🔺) 203 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 14 ms (+202.06% 🔺) 25 ms
thirdweb/react (minimal + tree-shaking) 19.54 KB (0%) 391 ms (0%) 64 ms (+71.5% 🔺) 454 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant