From 6909fb385116ce2b97902d31cc228cbd3b60ffdb Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Sat, 7 Jun 2025 18:43:42 +0100 Subject: [PATCH] assign `progress` in one go rather than checking for `NaN`, just `|| 0` - it will leave `0` as is, and convert any `NaN`s to `0` --- client/src/app/download-status.pipe.ts | 14 +++----------- client/src/app/torrent-status.pipe.ts | 12 ++---------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/client/src/app/download-status.pipe.ts b/client/src/app/download-status.pipe.ts index 100777f..0105727 100644 --- a/client/src/app/download-status.pipe.ts +++ b/client/src/app/download-status.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { Download } from './models/download.model'; import { FileSizePipe } from './filesize.pipe'; -@Pipe({ name: 'downloadStatus', }) +@Pipe({ name: 'downloadStatus' }) export class DownloadStatusPipe implements PipeTransform { constructor(private pipe: FileSizePipe) {} @@ -24,11 +24,7 @@ export class DownloadStatusPipe implements PipeTransform { } if (value.unpackingStarted) { - let progress = (value.bytesDone / value.bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (value.bytesDone / value.bytesTotal || 0) * 100; return `Unpacking ${progress.toFixed(2)}%`; } @@ -42,11 +38,7 @@ export class DownloadStatusPipe implements PipeTransform { } if (value.downloadStarted) { - let progress = (value.bytesDone / value.bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (value.bytesDone / value.bytesTotal || 0) * 100; const speed = this.pipe.transform(value.speed, 'filesize'); diff --git a/client/src/app/torrent-status.pipe.ts b/client/src/app/torrent-status.pipe.ts index 6b330d2..ac9da79 100644 --- a/client/src/app/torrent-status.pipe.ts +++ b/client/src/app/torrent-status.pipe.ts @@ -24,11 +24,7 @@ export class TorrentStatusPipe implements PipeTransform { if (downloading.length > 0) { const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0); const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0); - let progress = (bytesDone / bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (bytesDone / bytesTotal || 0) * 100; let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0); @@ -45,11 +41,7 @@ export class TorrentStatusPipe implements PipeTransform { if (unpacking.length > 0) { const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0); const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0); - let progress = (bytesDone / bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (bytesDone / bytesTotal || 0) * 100; return `Extracting file ${unpacking.length + unpacked.length}/${torrent.downloads.length} (${progress.toFixed( 2,