Feature: stabilize saved history, add code to cleanup old preferences, make loading preferences faster (which prevents a 'hang') when just logged in

This commit is contained in:
Pieter Vander Vennet 2025-04-06 19:17:19 +02:00
parent dc1e582664
commit c1d3f35d30
10 changed files with 249 additions and 146 deletions

View file

@ -246,11 +246,13 @@ export class OsmConnection {
}
public getPreference<T extends string = string>(
key: string,
defaultValue: string = undefined,
prefix: string = "mapcomplete-"
key: string, options?: {
defaultValue?: string,
prefix?: "mapcomplete-" | string,
saveToLocalStorage?: true | boolean
}
): UIEventSource<T | undefined> {
return <UIEventSource<T>>this.preferencesHandler.getPreference(key, defaultValue, prefix)
return <UIEventSource<T>>this.preferencesHandler.getPreference(key, options?.defaultValue, options?.prefix ?? "mapcomplete-")
}
public LogOut() {
@ -731,4 +733,24 @@ export class OsmConnection {
return { api: "offline", gpx: "offline", database: "online" }
}
}
public getCurrentChangesetFor(theme: string) {
return UIEventSource.asObject<{ id: number, opened: number }>(
this.GetPreference(
"current-changeset-" + theme
),
undefined
)
}
/**
* Returns the names of the themes that have an open changeset
*/
public getAllOpenChangesetsPreferences(): Store<string[]> {
const prefix = "current-changeset-"
return this.preferencesHandler.allPreferences.map(dict =>
Object.keys(dict)
.filter(k => k.startsWith(prefix))
.map(k => k.substring(prefix.length)))
}
}