Refine upload UX, fix add all progress indicator
This commit is contained in:
parent
aa7390df83
commit
7d3cef4f9d
@ -73,11 +73,17 @@ export default function AdminAddAllUploads({
|
|||||||
addedUploadUrls.current = updatedUrls;
|
addedUploadUrls.current = updatedUrls;
|
||||||
return updatedUrls;
|
return updatedUrls;
|
||||||
});
|
});
|
||||||
setAddingProgress((
|
setAddingProgress((current = 0) => {
|
||||||
// eslint-disable-next-line max-len
|
const updatedProgress = (
|
||||||
(((addedUploadUrls.current.length || 1) - 1) + (data?.progress ?? 0)) /
|
(
|
||||||
storageUrls.length
|
((addedUploadUrls.current.length || 1) - 1) +
|
||||||
) * 0.95);
|
(data?.progress ?? 0)
|
||||||
|
) /
|
||||||
|
storageUrls.length
|
||||||
|
) * 0.95;
|
||||||
|
// Prevent out-of-order updates causing progress to go backwards
|
||||||
|
return Math.max(current, updatedProgress);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setIsAdding(false);
|
setIsAdding(false);
|
||||||
|
|||||||
@ -44,10 +44,6 @@ export default function ImageInput({
|
|||||||
const [fileUploadIndex, setFileUploadIndex] = useState(0);
|
const [fileUploadIndex, setFileUploadIndex] = useState(0);
|
||||||
const [fileUploadName, setFileUploadName] = useState('');
|
const [fileUploadName, setFileUploadName] = useState('');
|
||||||
|
|
||||||
const uploadStatusText = filesLength > 1
|
|
||||||
? `${fileUploadIndex + 1} of ${filesLength}: ${fileUploadName}`
|
|
||||||
: fileUploadName;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4 min-w-0">
|
<div className="space-y-4 min-w-0">
|
||||||
<div className="flex items-center gap-2 sm:gap-4">
|
<div className="flex items-center gap-2 sm:gap-4">
|
||||||
@ -74,7 +70,9 @@ export default function ImageInput({
|
|||||||
primary
|
primary
|
||||||
>
|
>
|
||||||
{loading
|
{loading
|
||||||
? 'Uploading'
|
? filesLength > 1
|
||||||
|
? `Uploading ${fileUploadIndex + 1} of ${filesLength}`
|
||||||
|
: 'Uploading'
|
||||||
: 'Upload Photos'}
|
: 'Upload Photos'}
|
||||||
</ProgressButton>
|
</ProgressButton>
|
||||||
<input
|
<input
|
||||||
@ -225,7 +223,7 @@ export default function ImageInput({
|
|||||||
</label>
|
</label>
|
||||||
{showUploadStatus && filesLength > 0 &&
|
{showUploadStatus && filesLength > 0 &&
|
||||||
<div className="max-w-full truncate text-ellipsis">
|
<div className="max-w-full truncate text-ellipsis">
|
||||||
{uploadStatusText}
|
{fileUploadName}
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
<canvas
|
<canvas
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user