Skip to content
Snippets Groups Projects
Commit d9014d70 authored by Andréas Livet's avatar Andréas Livet
Browse files

Merge branch 'upload-tus' into 'develop'

Automatically select newly uploaded file

See merge request ademe-group/sofia/liriae_viewer!64
parents f2b11417 887bb7be
No related branches found
No related tags found
No related merge requests found
Pipeline #558276 canceled
......@@ -150,7 +150,6 @@ export default function ViewerSidePanel({
Authorization: accessToken!,
},
onError: function (error) {
console.error("Failed because: " + error);
setAlert({
description: error.message,
isOpen: true,
......@@ -161,7 +160,7 @@ export default function ViewerSidePanel({
},
onProgress: function (bytesUploaded, bytesTotal) {
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(0);
setUploadPercentage(percentage)
setUploadPercentage(percentage);
},
onSuccess: async function () {
setIsUploading(false);
......@@ -175,6 +174,13 @@ export default function ViewerSidePanel({
);
if (res.ok) {
const docs = await res.json();
const newDoc = docs.items.find(
(d: LiriaeDocument) =>
!liriaeDocuments.find((doc) => doc.id === d.id)
);
if (newDoc) {
navigateToDoc(newDoc);
}
setLiriaeDocuments(docs.items);
}
setAlert({
......@@ -185,9 +191,6 @@ export default function ViewerSidePanel({
autoHide: true,
});
},
onUploadUrlAvailable: () => {
console.log("Url available", upload.url);
},
});
// Check if there are any previous uploads to continue.
......@@ -275,8 +278,11 @@ export default function ViewerSidePanel({
}
}
}
// And load it
navigateToDoc(selectedDoc, pageNum);
// And load it only if its a new selectedDoc
// Prevent bug when url change, but useParams doesn't update it on time
if (!selectedDocument || selectedDocument.id !== selectedDoc.id) {
navigateToDoc(selectedDoc, pageNum);
}
}
}, [liriaeDocuments]);
......@@ -348,7 +354,9 @@ export default function ViewerSidePanel({
onClick={handleClick}
priority="secondary"
>
{isUploading ? `Envoi en cours ${uploadPercentage}%` : "Ajouter des fichiers"}
{isUploading
? `Envoi en cours ${uploadPercentage}%`
: "Ajouter des fichiers"}
{isUploading && (
<CircularProgress
size={24}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment