mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 11:42:30 +03:00
fix: properly update uppy state (#6252)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
7bf2a7c8d1
commit
f95f2b1dda
@ -28,44 +28,30 @@
|
||||
let state: UppyState<any, any> = upload.uppy.getState()
|
||||
let progress: number = state.totalProgress
|
||||
|
||||
$: state = upload.uppy.getState()
|
||||
$: progress = state.totalProgress
|
||||
$: files = Object.values(state.files)
|
||||
$: filesTotal = files.length
|
||||
$: filesComplete = files.filter((p) => p.progress?.uploadComplete).length
|
||||
|
||||
function handleProgress (totalProgress: number): void {
|
||||
progress = totalProgress
|
||||
}
|
||||
|
||||
function handleUploadProgress (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleUploadSuccess (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleFileRemoved (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleError (): void {
|
||||
function updateState (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
upload.uppy.on('error', handleError)
|
||||
upload.uppy.on('progress', handleProgress)
|
||||
upload.uppy.on('upload-progress', handleUploadProgress)
|
||||
upload.uppy.on('upload-success', handleUploadSuccess)
|
||||
upload.uppy.on('file-removed', handleFileRemoved)
|
||||
upload.uppy.on('error', updateState)
|
||||
upload.uppy.on('progress', updateState)
|
||||
upload.uppy.on('upload-progress', updateState)
|
||||
upload.uppy.on('upload-success', updateState)
|
||||
upload.uppy.on('file-removed', updateState)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
upload.uppy.off('error', handleError)
|
||||
upload.uppy.off('progress', handleProgress)
|
||||
upload.uppy.off('upload-progress', handleUploadProgress)
|
||||
upload.uppy.off('upload-success', handleUploadSuccess)
|
||||
upload.uppy.off('file-removed', handleFileRemoved)
|
||||
upload.uppy.off('error', updateState)
|
||||
upload.uppy.off('progress', updateState)
|
||||
upload.uppy.off('upload-progress', updateState)
|
||||
upload.uppy.off('upload-success', updateState)
|
||||
upload.uppy.off('file-removed', updateState)
|
||||
})
|
||||
|
||||
function handleClick (ev: MouseEvent): void {
|
||||
|
@ -40,28 +40,21 @@
|
||||
|
||||
let state: UppyState<any, any> = upload.uppy.getState()
|
||||
|
||||
$: state = upload.uppy.getState()
|
||||
$: files = Object.values(state.files)
|
||||
$: capabilities = state.capabilities ?? {}
|
||||
$: individualCancellation = 'individualCancellation' in capabilities && capabilities.individualCancellation
|
||||
|
||||
function updateState (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleComplete (): void {
|
||||
if (upload.uppy.getState().error === undefined) {
|
||||
dispatch('close')
|
||||
}
|
||||
}
|
||||
|
||||
function handleUploadError (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleUploadProgress (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleUploadSuccess (): void {
|
||||
state = upload.uppy.getState()
|
||||
}
|
||||
|
||||
function handleFileRemoved (): void {
|
||||
state = upload.uppy.getState()
|
||||
const files = upload.uppy.getFiles()
|
||||
@ -84,18 +77,18 @@
|
||||
|
||||
onMount(() => {
|
||||
upload.uppy.on('complete', handleComplete)
|
||||
upload.uppy.on('upload-error', handleUploadError)
|
||||
upload.uppy.on('upload-progress', handleUploadProgress)
|
||||
upload.uppy.on('upload-success', handleUploadSuccess)
|
||||
upload.uppy.on('file-removed', handleFileRemoved)
|
||||
upload.uppy.on('upload-error', updateState)
|
||||
upload.uppy.on('upload-progress', updateState)
|
||||
upload.uppy.on('upload-success', updateState)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
upload.uppy.off('complete', handleComplete)
|
||||
upload.uppy.off('upload-error', handleUploadError)
|
||||
upload.uppy.off('upload-progress', handleUploadProgress)
|
||||
upload.uppy.off('upload-success', handleUploadSuccess)
|
||||
upload.uppy.off('file-removed', handleFileRemoved)
|
||||
upload.uppy.off('upload-error', updateState)
|
||||
upload.uppy.off('upload-progress', updateState)
|
||||
upload.uppy.off('upload-success', updateState)
|
||||
})
|
||||
|
||||
function getFileError (file: UppyFile<any, any>): string | undefined {
|
||||
|
Loading…
Reference in New Issue
Block a user