Fix morescreen (which shows the custom themes now), remove invalid themes automatically
This commit is contained in:
parent
f771695c0b
commit
1e0a1fdf97
5 changed files with 31 additions and 11 deletions
|
@ -282,12 +282,7 @@ export class InitUiElements {
|
||||||
|
|
||||||
tabs.push({
|
tabs.push({
|
||||||
header: `<img src='./assets/add.svg'>`,
|
header: `<img src='./assets/add.svg'>`,
|
||||||
content: new VariableUiElement(State.state.osmConnection.userDetails.map(userdetails => {
|
content: new MoreScreen()
|
||||||
if(userdetails.csCount < State.userJourney.moreScreenUnlock){
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return new MoreScreen().Render()
|
|
||||||
}, [Locale.language]))
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,19 @@ export class OsmPreferences {
|
||||||
const self = this;
|
const self = this;
|
||||||
source.addCallback(str => {
|
source.addCallback(str => {
|
||||||
if (str === undefined || str === "") {
|
if (str === undefined || str === "") {
|
||||||
return
|
return;
|
||||||
|
}
|
||||||
|
if(str === null){
|
||||||
|
console.error("Deleting "+allStartWith);
|
||||||
|
let count = parseInt(length.data);
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
// Delete all the preferences
|
||||||
|
self.GetPreference(allStartWith + "-" + i, "")
|
||||||
|
.setData("");
|
||||||
|
}
|
||||||
|
self.GetPreference(allStartWith + "-length", "")
|
||||||
|
.setData("");
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -75,7 +87,6 @@ export class OsmPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
source.setData(str);
|
source.setData(str);
|
||||||
console.log("Long preference", key, "has", str.length, "chars");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
length.addCallback(l => {
|
length.addCallback(l => {
|
||||||
|
|
11
State.ts
11
State.ts
|
@ -205,6 +205,7 @@ export default class State {
|
||||||
if (allPreferences === undefined) {
|
if (allPreferences === undefined) {
|
||||||
return installedThemes;
|
return installedThemes;
|
||||||
}
|
}
|
||||||
|
const invalidThemes = []
|
||||||
for (const allPreferencesKey in allPreferences) {
|
for (const allPreferencesKey in allPreferences) {
|
||||||
const themename = allPreferencesKey.match(/^mapcomplete-installed-theme-(.*)-combined-length$/);
|
const themename = allPreferencesKey.match(/^mapcomplete-installed-theme-(.*)-combined-length$/);
|
||||||
if (themename && themename[1] !== "") {
|
if (themename && themename[1] !== "") {
|
||||||
|
@ -226,11 +227,19 @@ export default class State {
|
||||||
definition: customLayout.data
|
definition: customLayout.data
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Could not parse custom layout from preferences: ", allPreferencesKey, e, customLayout.data);
|
console.warn("Could not parse custom layout from preferences - deleting: ", allPreferencesKey, e, customLayout.data);
|
||||||
|
invalidThemes.push(themename[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const invalid of invalidThemes) {
|
||||||
|
console.error("Attempting to remove ", invalid)
|
||||||
|
this.osmConnection.GetLongPreference(
|
||||||
|
"installed-theme-" + invalid
|
||||||
|
).setData(null);
|
||||||
|
}
|
||||||
|
|
||||||
return installedThemes;
|
return installedThemes;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,6 @@ export class TabbedComponent extends UIElement {
|
||||||
let element = elements[i];
|
let element = elements[i];
|
||||||
this.headers.push(Translations.W(element.header).onClick(() => self._source.setData(i)));
|
this.headers.push(Translations.W(element.header).onClick(() => self._source.setData(i)));
|
||||||
const content = Translations.W(element.content)
|
const content = Translations.W(element.content)
|
||||||
this.ListenTo(content)
|
|
||||||
this.content.push(content);
|
this.content.push(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +33,7 @@ export class TabbedComponent extends UIElement {
|
||||||
headerBar = "<div class='tabs-header-bar'>" + headerBar + "</div>"
|
headerBar = "<div class='tabs-header-bar'>" + headerBar + "</div>"
|
||||||
|
|
||||||
const content = this.content[this._source.data];
|
const content = this.content[this._source.data];
|
||||||
|
console.log("Rendering tab", this._source.data);
|
||||||
return headerBar + "<div class='tab-content'>" + (content?.Render() ?? "") + "</div>";
|
return headerBar + "<div class='tab-content'>" + (content?.Render() ?? "") + "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,15 @@ import {Layout} from "../Customizations/Layout";
|
||||||
|
|
||||||
export class MoreScreen extends UIElement {
|
export class MoreScreen extends UIElement {
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(State.state.locationControl);
|
super(State.state.locationControl);
|
||||||
this.ListenTo(State.state.osmConnection.userDetails);
|
this.ListenTo(State.state.osmConnection.userDetails);
|
||||||
this.ListenTo(State.state.installedThemes);
|
this.ListenTo(State.state.installedThemes);
|
||||||
|
|
||||||
|
State.state.installedThemes.addCallback(themes => {
|
||||||
|
console.log("INSTALLED THEMES COUNT:", themes.length)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private createLinkButton(layout: Layout, customThemeDefinition: string = undefined) {
|
private createLinkButton(layout: Layout, customThemeDefinition: string = undefined) {
|
||||||
|
@ -68,6 +72,7 @@ export class MoreScreen extends UIElement {
|
||||||
|
|
||||||
InnerRender(): string {
|
InnerRender(): string {
|
||||||
|
|
||||||
|
console.log("Inner rendering MORE")
|
||||||
const tr = Translations.t.general.morescreen;
|
const tr = Translations.t.general.morescreen;
|
||||||
|
|
||||||
const els: UIElement[] = []
|
const els: UIElement[] = []
|
||||||
|
|
Loading…
Reference in a new issue