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`);
|
||||
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
6
src/typings.d.ts
vendored
@@ -197,9 +197,9 @@ interface IQueue {
|
||||
interface IUpdateStatus {
|
||||
running: boolean
|
||||
statusMap: {
|
||||
COMPLETE: number,
|
||||
RUNNING: number,
|
||||
PENDING: number
|
||||
COMPLETE?: IManga[],
|
||||
RUNNING?: IManga[],
|
||||
PENDING?: IManga[]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user