fix library update progress rendering (#210)

* Fix library update progress rendering

The websocket sends a list with mangas for each category (completed, running, pending) instead of a number.
This resulted in the progress to always be 0

* Prevent TypeError

The "UpdateStatus" can have a "statusMap" that contains not data.

Co-authored-by: schroda <github@dasch.simplelogin.com>
This commit is contained in:
Daniel
2023-01-01 17:58:23 +01:00
committed by GitHub
parent 2e3f57677e
commit 34bafee3aa
2 changed files with 7 additions and 5 deletions

View File

@@ -46,10 +46,12 @@ function UpdateChecker() {
const wsc = new WebSocket(`${baseWebsocketUrl}/api/v1/update`);
wsc.onmessage = (e) => {
const data = JSON.parse(e.data) as IUpdateStatus;
const { COMPLETE, RUNNING, PENDING } = data.statusMap;
const { COMPLETE = [], RUNNING = [], PENDING = [] } = data.statusMap;
setLoading(data.running);
const currentProgress = 100 * (COMPLETE / (COMPLETE + RUNNING + PENDING));
const currentProgress = 100 * (
COMPLETE.length / (COMPLETE.length + RUNNING.length + PENDING.length)
);
setProgress(Number.isNaN(currentProgress) ? 0 : currentProgress);
};

6
src/typings.d.ts vendored
View File

@@ -197,9 +197,9 @@ interface IQueue {
interface IUpdateStatus {
running: boolean
statusMap: {
COMPLETE: number,
RUNNING: number,
PENDING: number
COMPLETE?: IManga[],
RUNNING?: IManga[],
PENDING?: IManga[]
}
}