Save layoutconfigJSON as preferences, the are saved in the morescreen

This commit is contained in:
pietervdvn 2022-02-14 15:41:14 +01:00
parent c874afc745
commit 6cb5803efd
6 changed files with 44 additions and 10 deletions

View file

@ -72,7 +72,7 @@ export default class DetermineLayout {
public static LoadLayoutFromHash( public static LoadLayoutFromHash(
userLayoutParam: UIEventSource<string> userLayoutParam: UIEventSource<string>
): LayoutConfig | null { ): (LayoutConfig & {definition: LayoutConfigJson}) | null {
let hash = location.hash.substr(1); let hash = location.hash.substr(1);
let json: any; let json: any;
@ -113,7 +113,9 @@ export default class DetermineLayout {
const layoutToUse = DetermineLayout.prepCustomTheme(json) const layoutToUse = DetermineLayout.prepCustomTheme(json)
userLayoutParam.setData(layoutToUse.id); userLayoutParam.setData(layoutToUse.id);
return new LayoutConfig(layoutToUse, false); const config = new LayoutConfig(layoutToUse, false);
config["definition"] = json
return <any> config
} catch (e) { } catch (e) {
console.error(e) console.error(e)
if (hash === undefined || hash.length < 10) { if (hash === undefined || hash.length < 10) {

View file

@ -68,7 +68,8 @@ export default class UserRelatedState extends ElementsState {
id: this.layoutToUse.id, id: this.layoutToUse.id,
icon: this.layoutToUse.icon, icon: this.layoutToUse.icon,
title: this.layoutToUse.title.translations, title: this.layoutToUse.title.translations,
shortDescription: this.layoutToUse.shortDescription.translations shortDescription: this.layoutToUse.shortDescription.translations,
definition: this.layoutToUse["definition"]
})) }))
} }

View file

@ -406,12 +406,31 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
} }
} }
class PreparePersonalTheme extends DesugaringStep<LayoutConfigJson> {
private readonly _state: DesugaringContext;
constructor(state: DesugaringContext) {
super("Adds every public layer to the personal theme",["layers"],"PreparePersonalTheme");
this._state = state;
}
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
if(json.id !== "personal"){
return {result: json}
}
json.layers = Array.from(this._state.sharedLayers.keys())
return {result: json};
}
}
export class PrepareTheme extends Fuse<LayoutConfigJson> { export class PrepareTheme extends Fuse<LayoutConfigJson> {
constructor(state: DesugaringContext) { constructor(state: DesugaringContext) {
super( super(
"Fully prepares and expands a theme", "Fully prepares and expands a theme",
new PreparePersonalTheme(state),
new OnEveryConcat("layers", new SubstituteLayer(state)), new OnEveryConcat("layers", new SubstituteLayer(state)),
new SetDefault("socialImage", "assets/SocialImage.png", true), new SetDefault("socialImage", "assets/SocialImage.png", true),
new OnEvery("layers", new PrepareLayer(state)), new OnEvery("layers", new PrepareLayer(state)),

View file

@ -105,8 +105,9 @@ export default class FilterConfig {
if(this.options.length > 1){ if(this.options.length > 1){
defaultValue = ""+this.defaultSelection defaultValue = ""+this.defaultSelection
}else{ }else{
// Only a single option
if(this.defaultSelection > 0){ if(this.defaultSelection > 0){
defaultValue = ""+this.defaultSelection defaultValue = "true"
} }
} }
const qp = QueryParameters.GetQueryParameter("filter-" + this.id, defaultValue, "State of filter " + this.id) const qp = QueryParameters.GetQueryParameter("filter-" + this.id, defaultValue, "State of filter " + this.id)

View file

@ -20,7 +20,6 @@ import Toggle from "../Input/Toggle";
import {OsmConnection} from "../../Logic/Osm/OsmConnection"; import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import ContributorCount from "../../Logic/ContributorCount"; import ContributorCount from "../../Logic/ContributorCount";
import {icon} from "leaflet";
import Img from "../Base/Img"; import Img from "../Base/Img";
export class OpenIdEditor extends VariableUiElement { export class OpenIdEditor extends VariableUiElement {
@ -211,7 +210,11 @@ export default class CopyrightPanel extends Combine {
private static IconAttribution(iconPath: string): BaseUIElement { private static IconAttribution(iconPath: string): BaseUIElement {
if (iconPath.startsWith("http")) { if (iconPath.startsWith("http")) {
try{
iconPath = "." + new URL(iconPath).pathname; iconPath = "." + new URL(iconPath).pathname;
}catch(e){
console.error(e)
}
} }
const license: SmallLicense = CopyrightPanel.LicenseObject[iconPath] const license: SmallLicense = CopyrightPanel.LicenseObject[iconPath]

View file

@ -9,7 +9,7 @@ import BaseUIElement from "../BaseUIElement";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {UIEventSource} from "../../Logic/UIEventSource"; import {UIEventSource} from "../../Logic/UIEventSource";
import Loc from "../../Models/Loc"; import Loc from "../../Models/Loc";
import {OsmConnection} from "../../Logic/Osm/OsmConnection"; import UserDetails, {OsmConnection} from "../../Logic/Osm/OsmConnection";
import UserRelatedState from "../../Logic/State/UserRelatedState"; import UserRelatedState from "../../Logic/State/UserRelatedState";
import Toggle from "../Input/Toggle"; import Toggle from "../Input/Toggle";
import {Utils} from "../../Utils"; import {Utils} from "../../Utils";
@ -52,7 +52,8 @@ export default class MoreScreen extends Combine {
id: string, id: string,
icon: string, icon: string,
title: any, title: any,
shortDescription: any shortDescription: any,
definition?: any
}, isCustom: boolean = false }, isCustom: boolean = false
): ):
BaseUIElement { BaseUIElement {
@ -87,6 +88,11 @@ export default class MoreScreen extends Combine {
linkPrefix = `${path}/theme.html?userlayout=${layout.id}&` linkPrefix = `${path}/theme.html?userlayout=${layout.id}&`
} }
let hash = ""
if(layout.definition !== undefined){
hash = "#"+btoa(JSON.stringify(layout.definition))
}
const linkText = currentLocation?.map(currentLocation => { const linkText = currentLocation?.map(currentLocation => {
const params = [ const params = [
["z", currentLocation?.zoom], ["z", currentLocation?.zoom],
@ -95,10 +101,11 @@ export default class MoreScreen extends Combine {
].filter(part => part[1] !== undefined) ].filter(part => part[1] !== undefined)
.map(part => part[0] + "=" + part[1]) .map(part => part[0] + "=" + part[1])
.join("&") .join("&")
return `${linkPrefix}${params}`; return `${linkPrefix}${params}${hash}`;
}) ?? new UIEventSource<string>(`${linkPrefix}`) }) ?? new UIEventSource<string>(`${linkPrefix}`)
return new SubtleButton(layout.icon, return new SubtleButton(layout.icon,
new Combine([ new Combine([
`<dt class='text-lg leading-6 font-medium text-gray-900 group-hover:text-blue-800'>`, `<dt class='text-lg leading-6 font-medium text-gray-900 group-hover:text-blue-800'>`,
@ -134,7 +141,8 @@ export default class MoreScreen extends Combine {
id: string id: string
icon: string, icon: string,
title: any, title: any,
shortDescription: any shortDescription: any,
definition?: any
} = JSON.parse(str) } = JSON.parse(str)
return MoreScreen.createLinkButton(state, value, true) return MoreScreen.createLinkButton(state, value, true)