forked from MapComplete/MapComplete
Move unofficial theme logic into UserRelatedState; fix updating of longPreferences
This commit is contained in:
parent
c5a6b803ec
commit
d0b5163ff0
3 changed files with 67 additions and 48 deletions
|
@ -1,10 +1,12 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import UserDetails, {OsmConnection} from "./OsmConnection";
|
||||
import {Utils} from "../../Utils";
|
||||
import {DomEvent} from "leaflet";
|
||||
import preventDefault = DomEvent.preventDefault;
|
||||
|
||||
export class OsmPreferences {
|
||||
|
||||
public preferences = new UIEventSource<any>({}, "all-osm-preferences");
|
||||
public preferences = new UIEventSource<Record<string, string>>({}, "all-osm-preferences");
|
||||
private readonly preferenceSources = new Map<string, UIEventSource<string>>()
|
||||
private auth: any;
|
||||
private userDetails: UIEventSource<UserDetails>;
|
||||
|
@ -35,7 +37,7 @@ export class OsmPreferences {
|
|||
|
||||
const allStartWith = prefix + key + "-combined";
|
||||
// Gives the number of combined preferences
|
||||
const length = this.GetPreference(allStartWith + "-length", "");
|
||||
const length = this.GetPreference(allStartWith + "-length", "", "");
|
||||
|
||||
if( (allStartWith + "-length").length > 255){
|
||||
throw "This preference key is too long, it has "+key.length+" characters, but at most "+(255 - "-length".length - "-combined".length - prefix.length)+" characters are allowed"
|
||||
|
@ -51,10 +53,10 @@ export class OsmPreferences {
|
|||
let count = parseInt(length.data);
|
||||
for (let i = 0; i < count; i++) {
|
||||
// Delete all the preferences
|
||||
self.GetPreference(allStartWith + "-" + i, "")
|
||||
self.GetPreference(allStartWith + "-" + i, "", "")
|
||||
.setData("");
|
||||
}
|
||||
self.GetPreference(allStartWith + "-length", "")
|
||||
self.GetPreference(allStartWith + "-length", "", "")
|
||||
.setData("");
|
||||
return
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ export class OsmPreferences {
|
|||
if (i > 100) {
|
||||
throw "This long preference is getting very long... "
|
||||
}
|
||||
self.GetPreference(allStartWith + "-" + i, "").setData(str.substr(0, 255));
|
||||
self.GetPreference(allStartWith + "-" + i, "","").setData(str.substr(0, 255));
|
||||
str = str.substr(255);
|
||||
i++;
|
||||
}
|
||||
|
@ -107,6 +109,9 @@ export class OsmPreferences {
|
|||
}
|
||||
|
||||
public GetPreference(key: string, defaultValue : string = undefined, prefix: string = "mapcomplete-"): UIEventSource<string> {
|
||||
if(key.startsWith(prefix) && prefix !== ""){
|
||||
console.trace("A preference was requested which has a duplicate prefix in its key. This is probably a bug")
|
||||
}
|
||||
key = prefix + key;
|
||||
key = key.replace(/[:\\\/"' {}.%]/g, '')
|
||||
if (key.length >= 255) {
|
||||
|
@ -147,7 +152,7 @@ export class OsmPreferences {
|
|||
const matches = prefixes.some(prefix => key.startsWith(prefix))
|
||||
if (matches) {
|
||||
console.log("Clearing ", key)
|
||||
self.GetPreference(key, "").setData("")
|
||||
self.GetPreference(key, "", "").setData("")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue