Skip to content

Commit

Permalink
@uppy/status-bar: fix ETA when Uppy recovers its state (#4525)
Browse files Browse the repository at this point in the history
It was showing NaN seconds left.
  • Loading branch information
aduh95 committed Jun 27, 2023
1 parent ae3a0e7 commit 692481a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/@uppy/status-bar/src/StatusBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 692481a

Please sign in to comment.