Skip to content

Commit

Permalink
fix video uploads and too many re-renders issue during upload progres…
Browse files Browse the repository at this point in the history
…s in tus
  • Loading branch information
victorchrollo14 committed Oct 2, 2024
1 parent e389bbb commit 88c7db9
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function ContentsUploadPage() {

const pendingUploads = useRef(0);
const uploadPropsRef = useRef();
const prevTime = useRef(Date.now());

const [open, setOpen] = useState(false);
const [isClient, setIsClient] = useState(false);
Expand Down Expand Up @@ -330,9 +331,6 @@ function ContentsUploadPage() {
if (items[0]['file']['type'].startsWith('image')) {
ctype = 'Image';
}
if (items[0]['file']['type'].startsWith('video')) {
ctype = 'Video';
}

return {
options: {
Expand All @@ -354,7 +352,14 @@ function ContentsUploadPage() {
});

useItemProgressListener((item) => {
updateItems(item, 'progress');
const MIN_TIME_ELAPSED = 300;
const currentTime = Date.now();
const timeElapsed = currentTime - prevTime.current;

if (timeElapsed >= MIN_TIME_ELAPSED) {
updateItems(item, 'progress');
prevTime.current = currentTime;
}
});

useItemErrorListener((item) => {
Expand Down

0 comments on commit 88c7db9

Please sign in to comment.