Skip to content

Commit

Permalink
Merge pull request #89 from ebi-uniprot/dev2
Browse files Browse the repository at this point in the history
fixed indefinite download status update
  • Loading branch information
prabh-t authored Jun 17, 2024
2 parents 76809cf + 56f427e commit b70aad5
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/ui/pages/download/DownloadPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DefaultPageLayout from "../../layout/DefaultPageLayout";
import React, {useEffect, useState} from "react";
import React, {useEffect, useRef, useState} from "react";
import "./DownloadPage.css";
import {getDownloadStatus} from "../../../services/ProtVarService";
import {LOCAL_DOWNLOADS, PV_FTP, TITLE} from "../../../constants/const"
Expand Down Expand Up @@ -27,22 +27,30 @@ downloadStatusIcon[-1] = 'download-na';
function DownloadPageContent() {
const {getValue, setValue} = useLocalStorageContext();
const [downloads, setDownloads] = useState<DownloadRecord[]>(() => getValue(LOCAL_DOWNLOADS) || [])
const downloadsRef = useRef<DownloadRecord[]>(downloads); // useRef to hold the current downloads state

useEffect(() => {
document.title = 'Downloads - ' + TITLE;
const ids = downloads.map(d => d.downloadId)
downloadsRef.current = downloads;
}, [downloads]);

useEffect(() => {
const updateDownloadStatus = () => {
const ids = downloadsRef.current.map((d) => d.downloadId);
getDownloadStatus(ids).then((response) => {
const updatedDownloads = downloads.map(d => {
if (d.downloadId in response.data) {
d.status = response.data[d.downloadId]
}
return d
})
setDownloads(updatedDownloads)
setValue(LOCAL_DOWNLOADS, updatedDownloads)
})
}
, [downloads, setValue])
const updatedDownloads = downloadsRef.current.map((d) => {
if (d.downloadId in response.data) {
return { ...d, status: response.data[d.downloadId] };
}
return d;
});
setDownloads(updatedDownloads);
setValue(LOCAL_DOWNLOADS, updatedDownloads);
});
};

document.title = "Downloads - " + TITLE;
updateDownloadStatus();
}, [setValue]);

const handleDelete = (id: string) => {
const updatedDownloads = downloads.filter((d) => d.downloadId !== id);
Expand Down

0 comments on commit b70aad5

Please sign in to comment.