Skip to content
Snippets Groups Projects
Commit aa96ddde authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

fix(file-upload): fix concurrent file uploads

parent 8ccb0c6b
No related branches found
No related tags found
1 merge request!6Agree/Decline to work on a manuscript
...@@ -46,6 +46,7 @@ const FileSection = ({ ...@@ -46,6 +46,7 @@ const FileSection = ({
disabledFilepicker, disabledFilepicker,
dropSortableFile, dropSortableFile,
previewFile, previewFile,
requestPending,
}) => ( }) => (
<DropSection <DropSection
innerRef={instance => { innerRef={instance => {
...@@ -89,7 +90,7 @@ const FileSection = ({ ...@@ -89,7 +90,7 @@ const FileSection = ({
<SortableList <SortableList
beginDragProps={['id', 'index', 'name', 'listId']} beginDragProps={['id', 'index', 'name', 'listId']}
dragHandle={DragHandle} dragHandle={DragHandle}
dropItem={dropSortableFile} dropItem={requestPending() ? null : dropSortableFile}
items={files} items={files}
listId={listId} listId={listId}
listItem={FileItem} listItem={FileItem}
...@@ -113,12 +114,19 @@ export default compose( ...@@ -113,12 +114,19 @@ export default compose(
clearError: ({ setError }) => () => { clearError: ({ setError }) => () => {
setError(e => '') setError(e => '')
}, },
requestPending: ({ isFetching }) => () =>
Object.values(isFetching).some(Boolean),
}), }),
withHandlers({ withHandlers({
setError: ({ setError, clearError }) => err => { setError: ({ setError, clearError }) => err => {
setError(e => err, () => setTimeout(clearError, 3000)) setError(e => err, () => setTimeout(clearError, 3000))
}, },
disabledFilepicker: ({ files, maxFiles }) => () => files.length >= maxFiles, disabledFilepicker: ({
files,
maxFiles,
isFetching,
requestPending,
}) => () => files.length >= maxFiles || requestPending(),
}), }),
DropTarget( DropTarget(
'item', 'item',
...@@ -167,7 +175,14 @@ export default compose( ...@@ -167,7 +175,14 @@ export default compose(
NativeTypes.FILE, NativeTypes.FILE,
{ {
drop( drop(
{ files, maxFiles, addFile, allowedFileExtensions, setError }, {
files,
maxFiles,
addFile,
allowedFileExtensions,
setError,
requestPending,
},
monitor, monitor,
) { ) {
const [file] = monitor.getItem().files const [file] = monitor.getItem().files
...@@ -184,7 +199,7 @@ export default compose( ...@@ -184,7 +199,7 @@ export default compose(
) { ) {
setError('Invalid file type.') setError('Invalid file type.')
} else { } else {
addFile(file) !requestPending() && addFile(file)
} }
}, },
}, },
......
...@@ -122,7 +122,7 @@ export default compose( ...@@ -122,7 +122,7 @@ export default compose(
otherProps, otherProps,
dragProps, dragProps,
) => { ) => {
// do something if the files is not changing list // do something if the file is not changing list
const { listId: fromListId } = otherProps const { listId: fromListId } = otherProps
const { listId: toListId } = dragProps const { listId: toListId } = dragProps
if (fromListId === toListId) { if (fromListId === toListId) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment