forked from MapComplete/MapComplete
Remove unmaintained preferences page, re-add earlier visited installed themes (only remove themes)
This commit is contained in:
parent
4b6769d601
commit
7fe79600fb
6 changed files with 78 additions and 282 deletions
|
@ -3,12 +3,12 @@ import {OsmConnection} from "../Osm/OsmConnection";
|
|||
import {MangroveIdentity} from "../Web/MangroveReviews";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {QueryParameters} from "../Web/QueryParameters";
|
||||
import InstalledThemes from "../Actors/InstalledThemes";
|
||||
import {LocalStorageSource} from "../Web/LocalStorageSource";
|
||||
import {Utils} from "../../Utils";
|
||||
import Locale from "../../UI/i18n/Locale";
|
||||
import ElementsState from "./ElementsState";
|
||||
import SelectedElementTagsUpdater from "../Actors/SelectedElementTagsUpdater";
|
||||
import {log} from "util";
|
||||
|
||||
/**
|
||||
* The part of the state which keeps track of user-related stuff, e.g. the OSM-connection,
|
||||
|
@ -33,7 +33,10 @@ export default class UserRelatedState extends ElementsState {
|
|||
/**
|
||||
* WHich other themes the user previously visited
|
||||
*/
|
||||
public installedThemes: UIEventSource<{ layout: LayoutConfig; definition: string }[]>;
|
||||
public installedThemes: UIEventSource<{ id: string, // The id doubles as the URL
|
||||
icon: string,
|
||||
title: any,
|
||||
shortDescription: any}[]>;
|
||||
|
||||
|
||||
constructor(layoutToUse: LayoutConfig, options?:{attemptLogin : true | boolean}) {
|
||||
|
@ -69,9 +72,47 @@ export default class UserRelatedState extends ElementsState {
|
|||
})
|
||||
}
|
||||
|
||||
this.installedThemes = new InstalledThemes(
|
||||
this.osmConnection
|
||||
).installedThemes;
|
||||
this.installedThemes = this.osmConnection.GetLongPreference("installed-themes").map(
|
||||
str => {
|
||||
if(str === undefined || str === ""){
|
||||
return []
|
||||
}
|
||||
try{
|
||||
return JSON.parse(str)
|
||||
}catch(e){
|
||||
console.warn("Could not parse preference with installed themes due to ", e,"\nThe offending string is",str)
|
||||
return []
|
||||
}
|
||||
}, [],(installed => JSON.stringify(installed))
|
||||
)
|
||||
|
||||
|
||||
const self = this;
|
||||
this.osmConnection.isLoggedIn.addCallbackAndRunD(loggedIn => {
|
||||
if(!loggedIn){
|
||||
return
|
||||
}
|
||||
|
||||
if(this.layoutToUse.id.startsWith("http")){
|
||||
if(!this.installedThemes.data.some(installed => installed.id === this.layoutToUse.id)){
|
||||
|
||||
this.installedThemes.data.push({
|
||||
id: this.layoutToUse.id,
|
||||
icon: this.layoutToUse.icon,
|
||||
title: this.layoutToUse.title.translations,
|
||||
shortDescription: this.layoutToUse.shortDescription.translations
|
||||
})
|
||||
}
|
||||
this.installedThemes.ping()
|
||||
console.log("Registered "+this.layoutToUse.id+" as installed themes")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
})
|
||||
|
||||
|
||||
// Important: the favourite layers are initialized _after_ the installed themes, as these might contain an installedTheme
|
||||
this.favouriteLayers = LocalStorageSource.Get("favouriteLayers")
|
||||
|
@ -81,8 +122,7 @@ export default class UserRelatedState extends ElementsState {
|
|||
[],
|
||||
(layers) => Utils.Dedup(layers)?.join(";")
|
||||
);
|
||||
|
||||
|
||||
|
||||
this.InitializeLanguage();
|
||||
new SelectedElementTagsUpdater(this)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue