From 19c0ec44e9ca9b2ff459b12aaf5b64a6399a0115 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 23 Jun 2023 17:18:06 +0200 Subject: [PATCH] @uppy/status-bar: fix ETA when Uppy recovers its state It was showing NaN seconds left. --- packages/@uppy/status-bar/src/StatusBar.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/@uppy/status-bar/src/StatusBar.jsx b/packages/@uppy/status-bar/src/StatusBar.jsx index c6d704f4dd..9ed97eb689 100644 --- a/packages/@uppy/status-bar/src/StatusBar.jsx +++ b/packages/@uppy/status-bar/src/StatusBar.jsx @@ -97,6 +97,8 @@ export default class StatusBar extends UIPlugin { return 0 } + // When state is restored, lastUpdateTime is still nullish at this point. + this.#lastUpdateTime ??= performance.now() const dt = performance.now() - this.#lastUpdateTime if (dt === 0) { return Math.round((this.#previousETA ?? 0) / 100) / 10 @@ -130,14 +132,20 @@ export default class StatusBar extends UIPlugin { startUpload = () => { const { recoveredState } = this.uppy.getState() + this.#previousSpeed = null + this.#previousETA = null if (recoveredState) { + this.#previousUploadedBytes = Object.values(recoveredState.files) + .reduce((pv, { progress }) => pv + progress.bytesUploaded, 0) + + // We don't set `#lastUpdateTime` at this point because the upload won't + // actually resume until the user asks for it. + this.uppy.emit('restore-confirmed') return undefined } this.#lastUpdateTime = performance.now() this.#previousUploadedBytes = 0 - this.#previousSpeed = null - this.#previousETA = null return this.uppy.upload().catch(() => { // Error logged in Core })