Skip to content
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

chore: pass files to styleFieldArg #1012

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

Conversation

juliusmarminge
Copy link
Collaborator

@juliusmarminge juliusmarminge commented Oct 14, 2024

Closes #897

Give styleFieldArg the list of selected files

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced file upload components across various frameworks (React, Solid, Svelte, Vue) with a new files property for improved file management and context during uploads.
    • Updated onChange handlers in file input components for better handling of selected files.
    • Deprecated the onDrop method in favor of a unified onChange approach in the UploadDropzone component.

These updates improve the user experience by providing better feedback and control over file uploads.

Copy link

changeset-bot bot commented Oct 14, 2024

⚠️ No Changeset found

Latest commit: c68f2c9

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 Oct 14, 2024

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 5:10pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Oct 14, 2024 5:10pm

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces enhancements to the file upload components across multiple frameworks (React, Solid, Svelte, and Vue). Key changes include the addition of a files property of type File[] to various callback argument types, enabling better management and context of uploaded files. The styleFieldArg variable is updated to utilize useMemo for improved performance, and the uploadFiles function is modified to accommodate the new file state. The onChange handler is also updated to reflect changes in file selection.

Changes

File Path Change Summary
packages/react/src/components/button.tsx Added files: File[] to ButtonStyleFieldCallbackArgs, updated styleFieldArg with useMemo, modified uploadFiles and onChange.
packages/react/src/components/dropzone.tsx Added files: File[] to DropzoneStyleFieldCallbackArgs, updated styleFieldArg with useMemo.
packages/solid/src/components/button.tsx Added files to ButtonStyleFieldCallbackArgs, modified styleFieldArg and uploadFiles.
packages/solid/src/components/dropzone.tsx Added files: () => File[] to DropzoneStyleFieldCallbackArgs, updated styleFieldArg.
packages/svelte/src/lib/component/UploadButton.svelte Added files: File[] to ButtonStyleFieldCallbackArgs, updated styleFieldArg, modified onChange and uploadFiles.
packages/svelte/src/lib/component/UploadDropzone.svelte Added files: File[] to DropzoneStyleFieldCallbackArgs, deprecated onDrop, introduced onChange.
packages/vue/src/components/button.tsx Added files: File[] to ButtonStyleFieldCallbackArgs, updated styleFieldArg.
packages/vue/src/components/dropzone.tsx Added files: File[] to DropzoneStyleFieldCallbackArgs, updated styleFieldArg and onDrop.

Assessment against linked issues

Objective Addressed Explanation
Provide a value to show how many files are loaded into the component (#897)

Possibly related PRs

Suggested labels

@uploadthing/react, examples

Suggested reviewers

  • markflorkowski
  • t3dotgg

🐰 In the meadow, where files do play,
A new feature hops in, brightening the day.
With files in hand, we upload with glee,
A button that knows just how many there be!
So let’s click and share, let the uploads flow,
In our code garden, watch our features grow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

Copy link
Contributor

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 26.11KB See Treemap 📊
PR (2e972db) 26.11KB See Treemap 📊
Diff No change

Copy link

pkg-pr-new bot commented Oct 14, 2024

Open in Stackblitz

More templates

@uploadthing/nuxt

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/nuxt@1012

@uploadthing/react

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/react@1012

@uploadthing/solid

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/solid@1012

@uploadthing/svelte

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/svelte@1012

@uploadthing/vue

pnpm add https://pkg.pr.new/pingdotgg/uploadthing/@uploadthing/vue@1012

commit: c68f2c9

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: 1

🧹 Outside diff range and nitpick comments (9)
packages/solid/src/components/button.tsx (3)

179-179: LGTM: files signal correctly added to styleFieldArg.

The addition of the files signal to styleFieldArg is correct and aligns with the PR objectives. This change allows style and content callbacks to access the current file selection state.

For consistency with other properties in styleFieldArg, consider wrapping files in a getter function:

-    files,
+    files: () => files(),

This change would make files consistent with other reactive properties in styleFieldArg and potentially prevent unintended reactivity issues.


Line range hint 193-195: LGTM: Button content now reflects file selection state.

The changes in getButtonContent correctly implement dynamic content based on the number of selected files. This enhances the user experience by providing clear feedback about the current selection state.

For improved readability, consider extracting the file count logic into a separate function:

const getFileCountText = (count: number) => 
  `Upload ${count} file${count === 1 ? "" : "s"}`;

// In getButtonContent:
if (mode === "manual" && files().length > 0) {
  return getFileCountText(files().length);
}

This refactoring would make the code more modular and easier to maintain.


Inconsistencies found in the implementation of the files property across components.

  • Solid Components:

    • solid/src/components/button.tsx: files: () => File[];
    • solid/src/components/dropzone.tsx: files: () => File[];
  • Vue Components:

    • vue/src/components/button.tsx: files: File[];
    • vue/src/components/dropzone.tsx: files: () => File[];
  • React Components:

    • react/src/components/button.tsx: files: File[];
    • react/src/components/dropzone.tsx: files: File[];

Recommendation: Standardize the files property implementation across all components to ensure consistency and maintainability. Choose between using a direct array (File[]) or a reactive function (() => File[]) based on the framework's best practices and project requirements.

🔗 Analysis chain

Line range hint 1-324: Summary: PR objectives successfully implemented with minor suggestions for improvement.

The changes in this file successfully implement the PR objective of passing files to styleFieldArg. The UploadButton component now has access to the current file selection state, allowing for more dynamic and responsive UI. This addresses the linked issue #897 by providing better visibility of loaded files in the UploadDropzone component.

Key improvements:

  1. Added files property to ButtonStyleFieldCallbackArgs.
  2. Included files in styleFieldArg for use in style and content callbacks.
  3. Updated getButtonContent to reflect the current file selection state.

These changes enhance the component's functionality and user experience. The implementation is consistent with Solid.js patterns and best practices. Minor suggestions for improvement have been provided, but they don't impact the overall functionality of the changes.

To ensure that these changes are consistently applied across the codebase, please run the following verification script:

This script will help ensure that the files property is consistently implemented across different components and that it's being used correctly in styleFieldArg objects and for dynamic content generation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent implementation of `files` property across components

# Test 1: Check for `files` property in other component types
echo "Checking for 'files' property in other component types:"
rg --type typescript "type.*StyleFieldCallbackArgs" -A 10 | rg "files:"

# Test 2: Verify usage of `files` in `styleFieldArg` objects
echo "Checking usage of 'files' in styleFieldArg objects:"
rg --type typescript "styleFieldArg\s*=\s*\{" -A 10 | rg "files[,:]"

# Test 3: Check for dynamic content based on file selection
echo "Checking for dynamic content based on file selection:"
rg --type typescript "files\(\)\.length" -C 5

Length of output: 658


Script:

#!/bin/bash
# Description: Retry verification of `files` property implementation across TypeScript components using file glob patterns.

# Test 1: Check for `files` property in other component types
echo "Checking for 'files' property in other component types:"
rg --glob '*.ts' "type.*StyleFieldCallbackArgs" -A 10 | rg "files:"
rg --glob '*.tsx' "type.*StyleFieldCallbackArgs" -A 10 | rg "files:"

# Test 2: Verify usage of `files` in styleFieldArg objects
echo "Checking usage of 'files' in styleFieldArg objects:"
rg --glob '*.ts' "styleFieldArg\s*=\s*\{" -A 10 | rg "files[,:]"
rg --glob '*.tsx' "styleFieldArg\s*=\s*\{" -A 10 | rg "files[,:]"

# Test 3: Check for dynamic content based on file selection
echo "Checking for dynamic content based on file selection:"
rg --glob '*.ts' "files\(\)\.length" -C 5
rg --glob '*.tsx' "files\(\)\.length" -C 5

Length of output: 5872

packages/svelte/src/lib/component/UploadDropzone.svelte (1)

Line range hint 1-324: Consider further leveraging onChange for consistency

While the changes successfully implement the PR objectives, there's an opportunity to further improve the component's consistency:

  1. The onDrop prop is marked as deprecated in favor of onChange, but onDrop is still used in some places. Consider fully transitioning to onChange throughout the component.

  2. In the onDropCallback function, both onDrop and onChange are called. To align with the deprecation, consider removing the onDrop call and only using onChange.

  3. Update the documentation comments to reflect the preference for onChange over onDrop.

These changes would ensure better consistency and future-proof the component in line with the introduced changes.

packages/react/src/components/button.tsx (1)

222-232: LGTM: Memoization of styleFieldArg with files property

The use of useMemo for styleFieldArg is a good performance optimization. The addition of the files property aligns with the PR objective and allows for more flexible styling and content customization based on the selected files.

Consider destructuring the dependencies in the useMemo dependency array for better readability:

-  [fileTypes, files, state, uploadProgress],
+  [fileTypes, files, state, uploadProgress],

This change doesn't affect functionality but can make the code slightly more readable.

packages/vue/src/components/button.tsx (1)

203-205: LGTM: Improved styleFieldArg with file state

The addition of files: files.value to the styleFieldArg computed property is a good implementation that follows the type definition change. This makes the current list of selected files available for styling and content generation, enhancing the component's ability to reflect the file selection state visually.

For improved type safety, consider using a type assertion or explicitly defining the return type of the computed property:

const styleFieldArg = computed(
  (): ButtonStyleFieldCallbackArgs => ({
    // ... other properties
    files: files.value,
  })
);

This ensures that the returned object strictly adheres to the ButtonStyleFieldCallbackArgs type.

packages/solid/src/components/dropzone.tsx (2)

226-226: LGTM: Consistent implementation of files property

The addition of the files property to styleFieldArg is consistent with the type definition change and makes file information accessible for styling and rendering logic. This enhancement improves the component's flexibility in handling file-related UI updates.

For consistency with other properties in styleFieldArg, consider using an arrow function syntax:

-    files,
+    files: () => files(),

This change would make files consistent with other reactive properties in the object and explicitly show that it's a function returning the current files.


56-56: Overall impact: Enhanced file visibility without breaking changes

The additions of the files property to both DropzoneStyleFieldCallbackArgs and styleFieldArg successfully address the linked issue (#897) by providing better visibility of loaded files. These changes enhance the component's flexibility without introducing breaking changes or modifying existing behavior.

To fully leverage this new capability:

  1. Consider updating the component's documentation to highlight this new feature.
  2. You might want to add examples in the component's usage guide showing how to utilize the files property for custom styling or rendering based on the current file selection.
  3. If not already present, consider adding unit tests to ensure the files property is correctly populated and accessible in different scenarios.

Also applies to: 226-226

packages/react/src/components/dropzone.tsx (1)

253-264: Optimized styleFieldArg with file information

The use of useMemo for styleFieldArg is a good optimization. The addition of files to both the returned object and the dependency array ensures that styling can react to file selection changes.

For consistency, consider reordering the properties in the returned object to match the order in the DropzoneStyleFieldCallbackArgs type definition.

You could reorder the properties as follows:

 const styleFieldArg = useMemo(
   () =>
     ({
       ready: state !== "readying",
       isUploading: state === "uploading",
       uploadProgress,
+      files,
       fileTypes,
-      files,
       isDragActive,
     }) as DropzoneStyleFieldCallbackArgs,
   [fileTypes, files, state, uploadProgress, isDragActive],
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 07d3f48 and c68f2c9.

📒 Files selected for processing (8)
  • packages/react/src/components/button.tsx (2 hunks)
  • packages/react/src/components/dropzone.tsx (2 hunks)
  • packages/solid/src/components/button.tsx (2 hunks)
  • packages/solid/src/components/dropzone.tsx (2 hunks)
  • packages/svelte/src/lib/component/UploadButton.svelte (2 hunks)
  • packages/svelte/src/lib/component/UploadDropzone.svelte (2 hunks)
  • packages/vue/src/components/button.tsx (2 hunks)
  • packages/vue/src/components/dropzone.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (19)
packages/svelte/src/lib/component/UploadButton.svelte (4)

41-41: LGTM: Addition of files property enhances styling capabilities

The addition of the files: File[] property to ButtonStyleFieldCallbackArgs is a positive change. It allows the component to access the list of selected files for styling purposes, which aligns with the PR objective of passing files to styleFieldArg. This enhancement will enable more dynamic and context-aware styling based on the current state of file selection.


Line range hint 53-53: LGTM: Improved onChange prop definition

The updated onChange prop definition to accept (files: File[]) => void is a good improvement. This change allows the component to pass the entire array of selected files to the onChange callback, providing more flexibility in handling file changes. It supports the PR objectives by enabling better visibility and management of the files loaded into the UploadDropzone component.


139-139: LGTM: styleFieldArg now includes files for enhanced styling

The addition of the files property to the styleFieldArg reactive statement is a crucial update. This change makes the list of selected files available for styling purposes, allowing for more dynamic and context-aware styling based on the current state of file selection. It's consistent with the earlier addition of the files property to ButtonStyleFieldCallbackArgs and aligns perfectly with the PR objectives of providing better visibility regarding the files loaded into the UploadDropzone component.


41-41: Summary: Effective enhancements to file handling and styling capabilities

The changes made to the UploadButton component successfully address the PR objectives and align with the AI-generated summary. By adding the files property to ButtonStyleFieldCallbackArgs, updating the onChange prop, and including files in the styleFieldArg, the component now has improved capabilities for managing and providing visibility into selected files. These enhancements will allow for more dynamic styling and better user feedback, particularly addressing the issue of visually indicating when files have been loaded into the component.

Also applies to: 53-53, 139-139

packages/solid/src/components/button.tsx (1)

32-32: LGTM: Addition of files property aligns with PR objectives.

The addition of the files property to ButtonStyleFieldCallbackArgs is a well-implemented change that directly addresses the PR's goal. This allows components to access the current list of selected files, enabling more dynamic and responsive UI based on the file selection state.

packages/svelte/src/lib/component/UploadDropzone.svelte (2)

43-43: LGTM: Enhanced type definition for better file handling

The addition of files: File[]; to DropzoneStyleFieldCallbackArgs is a positive change. It aligns with the PR objective and enhances the component's ability to style based on the current file selection state. This improvement will lead to better type checking and autocompletion, making the component more robust and developer-friendly.


189-189: LGTM: Successfully implemented PR objective

The addition of files, to the styleFieldArg object directly fulfills the PR objective of passing files to styleFieldArg. This change enhances the component's ability to dynamically style itself based on the current file selection state. It's a crucial implementation that leverages the type definition update we saw earlier, providing more context to the styling callbacks and increasing the component's flexibility.

packages/react/src/components/button.tsx (3)

35-35: LGTM: Addition of files property to ButtonStyleFieldCallbackArgs

The addition of the files: File[] property to ButtonStyleFieldCallbackArgs is consistent with the PR objective. This change allows access to the selected files for styling and content customization purposes, enhancing the component's flexibility.


Line range hint 1-368: Summary of changes and next steps

The visible changes in this file align with the PR objectives and enhance the UploadButton component's flexibility and performance. The addition of the files property to ButtonStyleFieldCallbackArgs and the memoization of styleFieldArg are positive improvements.

However, some changes mentioned in the AI-generated summary, particularly those related to file handling logic, are not visible in the provided code segment. To ensure a comprehensive review:

  1. Please run the verification script provided in the previous comment to check for changes in the uploadFiles function and onChange handler.
  2. If the changes are present, consider updating the diff to include these modifications for a more complete review.
  3. If the changes are not present, please implement the necessary updates to handle the new files state in both the uploadFiles function and the onChange handler.

Once these steps are completed, we can proceed with a final review of the entire implementation.


Line range hint 1-368: Verify changes to file handling logic

The AI-generated summary mentions modifications to the uploadFiles function and onChange handler to accommodate the new files state. However, these changes are not visible in the provided code segment. This could be due to the diff not showing removed lines or old code.

To ensure all necessary changes have been implemented, please run the following script to check for modifications to the uploadFiles function and onChange handler:

Please review the output to confirm that the necessary changes to handle the files state have been implemented in both the uploadFiles function and the onChange handler.

✅ Verification successful

File handling logic verified successfully.

The uploadFiles function and the onChange handler have been correctly updated to manage the files state as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify changes to file handling logic in the UploadButton component

# Check for changes in the uploadFiles function
echo "Checking uploadFiles function:"
rg -U --type typescript 'const uploadFiles = useCallback\(' -A 10 packages/react/src/components/button.tsx

# Check for changes in the onChange handler
echo "Checking onChange handler:"
rg -U --type typescript 'onChange: \(e: React\.ChangeEvent<HTMLInputElement>\) =>' -A 15 packages/react/src/components/button.tsx

Length of output: 444


Script:

#!/bin/bash
# Description: Verify changes to file handling logic in the UploadButton component

# Check for changes in the uploadFiles function
echo "Checking uploadFiles function:"
rg -U -g "*.tsx" 'const uploadFiles = useCallback\(' -A 10 packages/react/src/components/button.tsx

# Check for changes in the onChange handler
echo "Checking onChange handler:"
rg -U -g "*.tsx" 'onChange: \(e: React\.ChangeEvent<HTMLInputElement>\) =>' -A 15 packages/react/src/components/button.tsx

Length of output: 1088

packages/vue/src/components/button.tsx (2)

33-33: LGTM: Enhanced type definition for better file state management

The addition of the files: File[] property to ButtonStyleFieldCallbackArgs is a positive change. It allows the component to access the current list of selected files, which can be used for dynamic styling and content generation based on the file selection state. This enhancement aligns well with the PR objective and improves the component's ability to provide visual feedback about the upload process.


Line range hint 1-368: Summary: Successful implementation with room for enhancement

The changes in this PR successfully implement the objective of passing files to styleFieldArg. The implementation is consistent, type-safe, and improves the component's ability to manage file selection state. However, there's potential to further leverage this new capability throughout the component.

Consider implementing the suggested improvements to fully utilize the files property in rendering and styling logic. This would enhance the component's responsiveness to file selection state and provide better visual feedback to users.

Overall, this is a solid foundation for improving the UploadDropzone component's functionality as requested in the linked issue #897.

packages/solid/src/components/dropzone.tsx (1)

56-56: LGTM: Enhanced styling capabilities with file information

The addition of the files property to DropzoneStyleFieldCallbackArgs is a valuable enhancement. It allows the component to access the current list of files being handled, which can be utilized in rendering or styling logic. This reactive property (() => File[]) aligns well with Solid.js patterns and provides more contextual information for styling purposes.

packages/react/src/components/dropzone.tsx (2)

63-63: Enhances styling flexibility with file information

The addition of the files: File[]; property to DropzoneStyleFieldCallbackArgs is a positive change. It allows the component to adjust its styling based on the current file selection, which aligns with the PR objective of improving visibility for loaded files.


Line range hint 1-724: Summary: Enhanced file-aware styling capabilities

The changes in this file successfully address the PR objective of improving visibility for loaded files in the UploadDropzone component. The addition of the files property to DropzoneStyleFieldCallbackArgs and its integration into styleFieldArg allows for more dynamic styling based on the current file selection. The use of useMemo for styleFieldArg is a good performance optimization, especially when dealing with potentially large file lists.

These changes are minimal and focused, which reduces the risk of introducing new bugs while enhancing the component's flexibility. The overall structure and core functionality of the UploadDropzone component remain intact, with the primary focus on improving the styling logic by incorporating the current files into the style calculations.

packages/vue/src/components/dropzone.tsx (4)

52-52: LGTM: Addition of files property aligns with PR objectives

The addition of the files: File[] property to DropzoneStyleFieldCallbackArgs is a good implementation. It directly addresses the need for better visibility of loaded files in the UploadDropzone component, as outlined in the linked issue #897.


240-241: LGTM: Inclusion of files in styleFieldArg enhances component flexibility

The addition of files: files.value, to the styleFieldArg computed property is a good implementation. This change allows the component to access the current list of files when determining styles and behaviors, which is crucial for providing visual feedback about the upload state to the user.


Line range hint 1-1: Summary: Good progress, clarification needed on onDrop method

The changes to add the files property to DropzoneStyleFieldCallbackArgs and include it in the styleFieldArg computed property are well-implemented and align with the PR objectives. These modifications enhance the component's ability to manage and display uploaded files, addressing the visibility issue mentioned in #897.

However, there's a discrepancy between the AI-generated summary and the visible changes regarding updates to the onDrop method. Clarification on this point would be helpful to ensure all intended changes are properly implemented and reviewed.

Overall, the implementation is consistent, well-typed, and improves the functionality of the UploadDropzone component.


Line range hint 1-1: Clarification needed: Changes to onDrop method

The AI-generated summary mentioned updates to the onDrop method to set files.value to the accepted files. However, these changes are not visible in the current diff. Could you please clarify if these changes were made in a different commit or if they are still pending?

To verify the current state of the onDrop method, please run the following script:

✅ Verification successful

Changes to onDrop method confirmed

The onDrop method in packages/vue/src/components/dropzone.tsx correctly sets files.value to acceptedFiles. The review comment aligns with the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the current implementation of the onDrop method

# Search for the onDrop method in the file
rg -A 10 'const onDrop = \(acceptedFiles: File\[\]\) =>' packages/vue/src/components/dropzone.tsx

Length of output: 449

@@ -30,6 +30,7 @@ export type ButtonStyleFieldCallbackArgs = {
isUploading: boolean;
uploadProgress: number;
fileTypes: string[];
files: File[];
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider leveraging the new files property in the component

The changes successfully implement the PR objective of passing files to styleFieldArg. However, the new files property is not yet utilized in the component's render logic or style calculations. To fully leverage this enhancement, consider the following suggestions:

  1. Update the renderButton method to use files.value.length for displaying the number of selected files, replacing the current manual mode check:
if (mode === "manual" && files.value.length > 0) {
  return `Upload ${files.value.length} file${files.value.length === 1 ? "" : "s"}`;
}
  1. Enhance the labelClass computed property to reflect the file selection state:
state.value === "ready" && files.value.length > 0 && "bg-green-600",
  1. Update the content prop types to allow dynamic content based on the number of selected files.

These improvements would make the component more responsive to the file selection state and provide better visual feedback to users.

Also applies to: 203-205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant