Skip to content

Commit 03188c6

Browse files
committed
fix warc percent
1 parent e2c578e commit 03188c6

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/loader.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import prettyBytes from "pretty-bytes";
77
import { parseURLSchemeHostPath } from "./pageutils";
88
import { property } from "lit/decorators.js";
99
import type { LoadInfo } from "./item";
10+
import { ifDefined } from "lit/directives/if-defined.js";
1011

1112
// ===========================================================================
1213
/**
@@ -266,7 +267,7 @@ You can select a file to upload from the main page by clicking the 'Choose File.
266267
}
267268
}
268269

269-
onCancel() {
270+
async onCancel() {
270271
if (!this.worker) {
271272
return;
272273
}
@@ -275,6 +276,9 @@ You can select a file to upload from the main page by clicking the 'Choose File.
275276

276277
if (!this.noWebWorker) {
277278
this.worker.postMessage(msg);
279+
280+
await this.updateComplete;
281+
278282
this.dispatchEvent(
279283
new CustomEvent("coll-load-cancel", {
280284
bubbles: true,
@@ -354,7 +358,7 @@ You can select a file to upload from the main page by clicking the 'Choose File.
354358
name="pulse"
355359
easing="ease-in-out"
356360
duration="2000"
357-
?play=${this.isLoadingWacz}
361+
?play=${this.isLoadingWacz || !this.percent}
358362
>
359363
<fa-icon
360364
size="5rem"
@@ -436,15 +440,25 @@ You can select a file to upload from the main page by clicking the 'Choose File.
436440
}
437441

438442
private renderProgressBar() {
443+
// Calculate percentage based on currentSize and totalSize
444+
// if data is available before actual percent
445+
const percent =
446+
this.percent || (this.currentSize && this.totalSize)
447+
? ((this.currentSize / this.totalSize) * 100).toFixed(0)
448+
: 0;
449+
439450
return html`
440451
<progress
441452
id="progress"
442453
class="progress is-primary is-large"
443-
value="${this.percent}"
454+
value=${ifDefined(percent || undefined)}
444455
max="100"
445456
></progress>
446-
<label class="progress-label" for="progress">${this.percent}%</label>
447-
457+
${percent
458+
? html`
459+
<label class="progress-label" for="progress">${percent}%</label>
460+
`
461+
: nothing}
448462
${this.currentSize && this.totalSize
449463
? html` <div class="loaded-prog">
450464
Loaded

0 commit comments

Comments
 (0)