forked from MapComplete/MapComplete
Add a personal, configurable quest
This commit is contained in:
parent
7ec00a3301
commit
b36b103ed3
7 changed files with 55 additions and 54 deletions
|
@ -1,24 +1,22 @@
|
|||
import {UIEventSource} from "../UI/UIEventSource";
|
||||
import {UIElement} from "../UI/UIElement";
|
||||
|
||||
export class LocalStorageSource {
|
||||
|
||||
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
||||
|
||||
if (UIElement.runningFromConsole) {
|
||||
try {
|
||||
|
||||
// ignore when running from the console
|
||||
|
||||
const saved = localStorage.getItem(key);
|
||||
const source = new UIEventSource<string>(saved ?? defaultValue);
|
||||
|
||||
source.addCallback((data) => {
|
||||
localStorage.setItem(key, data);
|
||||
console.log("Wriging ", key, data)
|
||||
});
|
||||
return source;
|
||||
} catch (e) {
|
||||
return new UIEventSource<string>(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
const saved = localStorage.getItem(key);
|
||||
const source = new UIEventSource<string>(saved ?? defaultValue);
|
||||
|
||||
source.addCallback((data) => {
|
||||
localStorage.setItem(key, data);
|
||||
console.log("Wriging ", key, data)
|
||||
});
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
* Wraps the query parameters into UIEventSources
|
||||
*/
|
||||
import {UIEventSource} from "../UI/UIEventSource";
|
||||
import {UIElement} from "../UI/UIElement";
|
||||
|
||||
export class QueryParameters {
|
||||
|
||||
private static order: string [] = ["layout","test","z","lat","lon"];
|
||||
private static knownSources = QueryParameters.init();
|
||||
private static knownSources = {};
|
||||
private static initialized = false;
|
||||
private static defaults = {}
|
||||
|
||||
private static addOrder(key){
|
||||
|
@ -16,11 +18,13 @@ export class QueryParameters {
|
|||
}
|
||||
|
||||
private static init() {
|
||||
const knownSources = {}
|
||||
if(window === undefined){
|
||||
|
||||
if(this.initialized){
|
||||
return;
|
||||
}
|
||||
if (window.location.search) {
|
||||
this.initialized = true;
|
||||
|
||||
if (window?.location?.search) {
|
||||
const params = window.location.search.substr(1).split("&");
|
||||
for (const param of params) {
|
||||
const kv = param.split("=");
|
||||
|
@ -29,10 +33,9 @@ export class QueryParameters {
|
|||
const v = kv[1];
|
||||
const source = new UIEventSource<string>(v);
|
||||
source.addCallback(() => QueryParameters.Serialize())
|
||||
knownSources[key] = source;
|
||||
QueryParameters.knownSources[key] = source;
|
||||
}
|
||||
}
|
||||
return knownSources;
|
||||
}
|
||||
|
||||
private static Serialize() {
|
||||
|
@ -51,6 +54,9 @@ export class QueryParameters {
|
|||
}
|
||||
|
||||
public static GetQueryParameter(key: string, deflt: string): UIEventSource<string> {
|
||||
if(!this.initialized){
|
||||
this.init();
|
||||
}
|
||||
if (deflt !== undefined) {
|
||||
QueryParameters.defaults[key] = deflt;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue