Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
sadmann7 committed Apr 7, 2024
1 parent 487c4f7 commit 6625fa3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/file-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export function FileUploader({
onUpload,
progresses,
accept = { "image/*": [] },
multiple,
maxSize = 1024 * 1024 * 4,
maxFiles = 1,
multiple = false,
disabled = false,
className,
...props
Expand All @@ -83,7 +83,12 @@ export function FileUploader({

const onDrop = React.useCallback(
(acceptedFiles: File[], rejectedFiles: FileRejection[]) => {
if (files && files.length + acceptedFiles.length > maxFiles) {
if (!multiple || (maxFiles === 1 && rejectedFiles.length > 1)) {
toast.error("Cannot upload more than 1 file at a time")
return
}

if (files.length + acceptedFiles.length > maxFiles) {
toast.error(`Cannot upload more than ${maxFiles} files`)
return
}
Expand Down Expand Up @@ -125,7 +130,7 @@ export function FileUploader({
}
},

[files, maxFiles, onUpload, onValueChange]
[files, maxFiles, multiple, onUpload, onValueChange]
)

function onRemove(file: FileWithPreview) {
Expand Down

0 comments on commit 6625fa3

Please sign in to comment.