improve cancellation

This commit is contained in:
Murderlon 2025-11-11 14:08:27 +01:00
parent fb1ed0e9f4
commit 1f159074bf
No known key found for this signature in database
GPG key ID: 1FF861FF1DDBB953

View file

@ -3,6 +3,7 @@ import type {
Meta,
MinimalRequiredUppyFile,
UIPluginOptions,
UppyEventMap,
} from '@uppy/core'
import Uppy, { UIPlugin } from '@uppy/core'
import { FilterInput, SearchView } from '@uppy/provider-views'
@ -97,14 +98,20 @@ export default class ImageGenerator<
waitForEncoding: true,
assemblyOptions,
})
localUppy.on('transloadit:result', (_, result) => {
const onResult: UppyEventMap<M, B>['transloadit:result'] = (
stepName,
result,
) => {
const { results } = this.getPluginState()
// For some reason this event can be called twice with the same result
// so we check if we already have it before adding it to state.
if (!results.some((r) => r.id === result.id)) {
this.setPluginState({ results: [...results, result] })
}
this.setPluginState({ results: [...results, result], firstRun: false })
}
localUppy.on('transloadit:result', onResult)
// @ts-expect-error not typed because we do not depend on @uppy/dashboard
this.uppy.once('dashboard:close-panel', () => {
localUppy.cancelAll()
localUppy.off('transloadit:result', onResult)
this.setPluginState(defaultState)
})
try {
@ -118,7 +125,8 @@ export default class ImageGenerator<
await localUppy.upload()
} finally {
this.clearLoadingInterval()
this.setPluginState({ loading: false, firstRun: false })
localUppy.off('transloadit:result', onResult)
this.setPluginState({ loading: false })
}
}