forked from MapComplete/MapComplete
Add current location in localstorage, fixes #13
This commit is contained in:
parent
2a61ae6e1f
commit
89b78ee709
5 changed files with 28 additions and 25 deletions
|
@ -67,7 +67,7 @@ export class UIEventSource<T>{
|
|||
}
|
||||
|
||||
|
||||
public syncWith(otherSource: UIEventSource<T>){
|
||||
public syncWith(otherSource: UIEventSource<T>) : UIEventSource<T>{
|
||||
this.addCallback((latest) => otherSource.setData(latest));
|
||||
const self = this;
|
||||
otherSource.addCallback((latest) => self.setData(latest));
|
||||
|
@ -76,6 +76,7 @@ export class UIEventSource<T>{
|
|||
}else{
|
||||
otherSource.setData(this.data);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +1,7 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import {OsmConnection} from "../../Logic/OsmConnection";
|
||||
import {LocalStorageSource} from "../../Logic/LocalStorageSource";
|
||||
|
||||
|
||||
export default class Locale {
|
||||
public static language: UIEventSource<string> = Locale.getInitialLanguage();
|
||||
|
||||
private static getInitialLanguage() {
|
||||
// The key to save in local storage
|
||||
const LANGUAGE_KEY = 'language'
|
||||
|
||||
const lng = new UIEventSource("en");
|
||||
const saved = localStorage.getItem(LANGUAGE_KEY);
|
||||
lng.setData(saved);
|
||||
|
||||
|
||||
lng.addCallback(data => {
|
||||
console.log("Selected language", data);
|
||||
localStorage.setItem(LANGUAGE_KEY, data)
|
||||
});
|
||||
|
||||
return lng;
|
||||
}
|
||||
public static language: UIEventSource<string> = LocalStorageSource.Get('language', "en");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue