-
Notifications
You must be signed in to change notification settings - Fork 12
[UXIT-3464] Add compact Upload component #87
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Filecoin Pin UploadIPFS Artifacts:
Onchain verification:
Payment:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great @barbaraperic 👏
My only comment would be: centralize the logic file state management in a hook, if possible.
Currently, DragNDrop and UploadButton each use their own state and functions to manage files, but the logic is similar.
I would create a useFileState hook (name TBD) to abstract all of it, such as below, and call it in each file picker component.
import { useRef, useState } from 'react'
import { formatFileSize } from '@/utils/format-file-size'
type UseFileStateProps = {
maxSize: number
onUpload: (file: File) => void
}
export function useFileState({ maxSize, onUpload }: UseFileStateProps) {
const fileInputRef = useRef<HTMLInputElement>(null)
const [error, setError] = useState<string | null>(null)
function handleButtonClick() {
fileInputRef.current?.click()
}
function handleFileChange(e: React.ChangeEvent<HTMLInputElement>) {
const file = e.target.files?.[0]
if (file) {
if (file.size > maxSize) {
setError(`File is too large. Maximum size is ${formatFileSize(maxSize)}.`)
if (fileInputRef.current) fileInputRef.current.value = ''
return
}
setError(null)
onUpload(file)
if (fileInputRef.current) fileInputRef.current.value = ''
}
}
function clearFile() {
if (fileInputRef.current) fileInputRef.current.value = ''
}
return {
error,
fileInputRef,
handleButtonClick,
handleFileChange,
clearFile,
}
}(I haven't tested this)
| <input | ||
| accept={accept.join(',')} | ||
| className="hidden" | ||
| multiple={false} | ||
| onChange={handleFileChange} | ||
| ref={fileInputRef} | ||
| type="file" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe if you pass size here, the user will only be able to pick files with an appropriate size, hence rendering the use setError(File is too large. Maximum size is ${formatFileSize(maxSize)}.) unnecessary.
To be tested, maybe both are needed!
| <input | |
| accept={accept.join(',')} | |
| className="hidden" | |
| multiple={false} | |
| onChange={handleFileChange} | |
| ref={fileInputRef} | |
| type="file" | |
| <input | |
| accept={accept.join(',')} | |
| className="hidden" | |
| multiple={false} | |
| onChange={handleFileChange} | |
| ref={fileInputRef} | |
| type="file" | |
| size={maxSize} |
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/file#size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like that section is under “Getting information on selected files,” which is all about the File API, not HTML attribute? 👀
SgtPooki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not up to date on the mocks. are we supposed to remove the drag-n-drop functionality?
This commit introduces a new UploadButton component that allows users to upload files with error handling for file size limits. The component utilizes Radix UI for form control and includes a button with a loading state during uploads. It also provides user feedback for file size errors.
…and UploadButton components This commit updates the DragNDrop and UploadButton components to use a centralized MAX_FILE_SIZE constant instead of hardcoded values for maximum file size. Additionally, it improves the structure of the UploadButton component by adjusting the layout and error message handling for better user experience.
47d37bf to
b392827
Compare
Hm I honestly feel like they are too different for a shared hook... State Management
User Flow
Validation
UI
|
This commit introduces a new UploadButton component that allows users to upload files with error handling for file size limits. The component utilizes Radix UI for form control and includes a button with a loading state during uploads. It also provides user feedback for file size errors.
CleanShot.2025-11-05.at.11.46.18.mp4