Fix: add 'onbeforeunload' if images are uploading, see #1841

This commit is contained in:
Pieter Vander Vennet 2024-03-28 15:55:12 +01:00
parent 1c03e7ab07
commit ce7bc8fb6c
3 changed files with 14 additions and 3 deletions

View file

@ -3,9 +3,10 @@ import Constants from "../../Models/Constants"
import { UIEventSource } from "../UIEventSource" import { UIEventSource } from "../UIEventSource"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { Feature } from "geojson" import { Feature } from "geojson"
import { ImageUploadManager } from "../ImageProviders/ImageUploadManager"
export default class PendingChangesUploader { export default class PendingChangesUploader {
constructor(changes: Changes, selectedFeature: UIEventSource<Feature>) { constructor(changes: Changes, selectedFeature: UIEventSource<Feature>, uploader : ImageUploadManager) {
changes.pendingChanges changes.pendingChanges
.stabilized(Constants.updateTimeoutSec * 1000) .stabilized(Constants.updateTimeoutSec * 1000)
.addCallback(() => changes.flushChanges("Flushing changes due to timeout")) .addCallback(() => changes.flushChanges("Flushing changes due to timeout"))
@ -48,7 +49,9 @@ export default class PendingChangesUploader {
} }
function onunload(e) { function onunload(e) {
if (changes.pendingChanges.data.length == 0) { const pendingChanges = changes.pendingChanges.data.length
const uploadingImages = uploader.isUploading.data
if (pendingChanges == 0 && !uploadingImages) {
return return
} }
changes.flushChanges("onbeforeunload - probably closing or something similar") changes.flushChanges("onbeforeunload - probably closing or something similar")

View file

@ -24,6 +24,7 @@ export class ImageUploadManager {
private readonly _uploadRetriedSuccess: Map<string, UIEventSource<number>> = new Map() private readonly _uploadRetriedSuccess: Map<string, UIEventSource<number>> = new Map()
private readonly _osmConnection: OsmConnection private readonly _osmConnection: OsmConnection
private readonly _changes: Changes private readonly _changes: Changes
public readonly isUploading: Store<boolean>
constructor( constructor(
layout: LayoutConfig, layout: LayoutConfig,
@ -37,6 +38,13 @@ export class ImageUploadManager {
this._layout = layout this._layout = layout
this._osmConnection = osmConnection this._osmConnection = osmConnection
this._changes = changes this._changes = changes
const failed = this.getCounterFor(this._uploadFailed, "*")
const done = this.getCounterFor(this._uploadFinished, "*")
this.isUploading = this.getCounterFor(this._uploadStarted, "*").map(startedCount => {
return startedCount > failed.data + done.data
}, [failed, done])
} }
/** /**

View file

@ -810,7 +810,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
new MetaTagging(this) new MetaTagging(this)
new TitleHandler(this.selectedElement, this.featureProperties, this) new TitleHandler(this.selectedElement, this.featureProperties, this)
new ChangeToElementsActor(this.changes, this.featureProperties) new ChangeToElementsActor(this.changes, this.featureProperties)
new PendingChangesUploader(this.changes, this.selectedElement) new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
new SelectedElementTagsUpdater(this) new SelectedElementTagsUpdater(this)
new BackgroundLayerResetter(this.mapProperties.rasterLayer, this.availableLayers) new BackgroundLayerResetter(this.mapProperties.rasterLayer, this.availableLayers)
new PreferredRasterLayerSelector( new PreferredRasterLayerSelector(