Skip to content

Commit

Permalink
refactor: (ImageUploader) clear e.target.value immediately after retr…
Browse files Browse the repository at this point in the history
…ieving files
  • Loading branch information
awmleer committed May 9, 2022
1 parent be3d08f commit c1cfdde
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/image-uploader/demos/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const demoSrc =
'https://images.unsplash.com/photo-1567945716310-4745a6b7844b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=300&q=60'

export async function mockUpload(file: File) {
await sleep(3000000)
await sleep(3000)
return {
url: URL.createObjectURL(file),
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/image-uploader/image-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ export const ImageUploader: FC<ImageUploaderProps> = p => {
const { files: rawFiles } = e.target
if (!rawFiles) return
let files = [].slice.call(rawFiles) as File[]
e.target.value = '' // HACK: fix the same file doesn't trigger onChange

if (props.beforeUpload) {
e.target.value = ''
const postFiles = files.map(file => {
return processFile(file, files)
})
Expand Down Expand Up @@ -141,7 +141,6 @@ export const ImageUploader: FC<ImageUploaderProps> = p => {

setTasks(prev => [...prev, ...newTasks])

e.target.value = '' // HACK: fix the same file doesn't trigger onChange
await Promise.all(
newTasks.map(async currentTask => {
try {
Expand Down

0 comments on commit c1cfdde

Please sign in to comment.