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:
@@ -46,10 +46,12 @@ function UpdateChecker() {
|
|||||||
const wsc = new WebSocket(`${baseWebsocketUrl}/api/v1/update`);
|
const wsc = new WebSocket(`${baseWebsocketUrl}/api/v1/update`);
|
||||||
wsc.onmessage = (e) => {
|
wsc.onmessage = (e) => {
|
||||||
const data = JSON.parse(e.data) as IUpdateStatus;
|
const data = JSON.parse(e.data) as IUpdateStatus;
|
||||||
const { COMPLETE, RUNNING, PENDING } = data.statusMap;
|
const { COMPLETE = [], RUNNING = [], PENDING = [] } = data.statusMap;
|
||||||
|
|
||||||
setLoading(data.running);
|
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);
|
setProgress(Number.isNaN(currentProgress) ? 0 : currentProgress);
|
||||||
};
|
};
|
||||||
|
|||||||
6
src/typings.d.ts
vendored
6
src/typings.d.ts
vendored
@@ -197,9 +197,9 @@ interface IQueue {
|
|||||||
interface IUpdateStatus {
|
interface IUpdateStatus {
|
||||||
running: boolean
|
running: boolean
|
||||||
statusMap: {
|
statusMap: {
|
||||||
COMPLETE: number,
|
COMPLETE?: IManga[],
|
||||||
RUNNING: number,
|
RUNNING?: IManga[],
|
||||||
PENDING: number
|
PENDING?: IManga[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user