Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/status-bar: listen to upload event instead of button click #4563

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions packages/@uppy/status-bar/src/StatusBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@ 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
return this.uppy.upload().catch(() => {
// Error logged in Core
})
Expand Down Expand Up @@ -245,14 +229,35 @@ export default class StatusBar extends UIPlugin {
}
}

#onUploadStart = () => {
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
}
this.#lastUpdateTime = performance.now()
this.#previousUploadedBytes = 0
}

install () {
const { target } = this.opts
if (target) {
this.mount(target, this)
}
this.uppy.on('upload', this.#onUploadStart)
}

uninstall () {
this.unmount()
this.uppy.off('upload', this.#onUploadStart)
}
}