forked from MapComplete/MapComplete
Feat: remove possibility to load a custom theme via the hash, no longer necessary with a theme server
This commit is contained in:
parent
9bf013cd47
commit
a016a8f771
2 changed files with 2 additions and 177 deletions
|
@ -3,8 +3,6 @@ import { QueryParameters } from "./Web/QueryParameters"
|
|||
import { AllKnownLayouts } from "../Customizations/AllKnownLayouts"
|
||||
import { FixedUiElement } from "../UI/Base/FixedUiElement"
|
||||
import { Utils } from "../Utils"
|
||||
import { UIEventSource } from "./UIEventSource"
|
||||
import { LocalStorageSource } from "./Web/LocalStorageSource"
|
||||
import LZString from "lz-string"
|
||||
import { FixLegacyTheme } from "../Models/ThemeConfig/Conversion/LegacyJsonConvert"
|
||||
import { LayerConfigJson } from "../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
|
@ -27,7 +25,7 @@ export default class DetermineTheme {
|
|||
private static readonly loadCustomThemeParam = QueryParameters.GetQueryParameter(
|
||||
"userlayout",
|
||||
"false",
|
||||
"If not 'false', a custom (non-official) theme is loaded. This custom layout can be done in multiple ways: \n\n- The hash of the URL contains a base64-encoded .json-file containing the theme definition\n- The hash of the URL contains a lz-compressed .json-file, as generated by the custom theme generator\n- The parameter itself is an URL, in which case that URL will be downloaded. It should point to a .json of a theme"
|
||||
"If the parameter is an URL, it should point to a .json of a theme which will be loaded and used"
|
||||
)
|
||||
|
||||
public static getCustomDefinition(): string {
|
||||
|
@ -37,18 +35,6 @@ export default class DetermineTheme {
|
|||
return layoutFromBase64
|
||||
}
|
||||
|
||||
if (layoutFromBase64 !== "false") {
|
||||
// We have to load something from the hash (or from disk)
|
||||
const hash = Hash.hash.data
|
||||
try {
|
||||
JSON.parse(atob(hash))
|
||||
return atob(hash)
|
||||
} catch (e) {
|
||||
// We try to decode with lz-string
|
||||
JSON.parse(Utils.UnMinify(LZString.decompressFromBase64(hash)))
|
||||
return Utils.UnMinify(LZString.decompressFromBase64(hash))
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
@ -67,8 +53,7 @@ export default class DetermineTheme {
|
|||
try {
|
||||
new URL(l)
|
||||
console.log("Downloading remote layer " + l)
|
||||
const layerConfig = <LayerConfigJson>await Utils.downloadJson(l)
|
||||
layoutConfig.layers[i] = layerConfig
|
||||
layoutConfig.layers[i] = <LayerConfigJson>await Utils.downloadJson(l)
|
||||
} catch (_) {
|
||||
continue
|
||||
}
|
||||
|
@ -86,11 +71,6 @@ export default class DetermineTheme {
|
|||
return await DetermineTheme.LoadRemoteTheme(layoutFromBase64)
|
||||
}
|
||||
|
||||
if (layoutFromBase64 !== "false") {
|
||||
// We have to load something from the hash (or from disk)
|
||||
return await DetermineTheme.LoadLayoutFromHash(DetermineTheme.loadCustomThemeParam)
|
||||
}
|
||||
|
||||
let layoutId: string = undefined
|
||||
|
||||
const path = window.location.pathname.split("/").slice(-1)[0]
|
||||
|
@ -125,43 +105,6 @@ export default class DetermineTheme {
|
|||
return layouts.get(id)
|
||||
}
|
||||
|
||||
public static async LoadLayoutFromHash(
|
||||
userLayoutParam: UIEventSource<string>
|
||||
): Promise<ThemeConfig | null> {
|
||||
let hash = location.hash.substr(1)
|
||||
let json: any
|
||||
|
||||
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
|
||||
const dedicatedHashFromLocalStorage = LocalStorageSource.get(
|
||||
"user-layout-" + userLayoutParam.data?.replace(" ", "_")
|
||||
)
|
||||
if (dedicatedHashFromLocalStorage.data?.length < 10) {
|
||||
dedicatedHashFromLocalStorage.setData(undefined)
|
||||
}
|
||||
|
||||
const hashFromLocalStorage = LocalStorageSource.get("last-loaded-user-layout")
|
||||
if (hash.length < 10) {
|
||||
hash = dedicatedHashFromLocalStorage.data ?? hashFromLocalStorage.data
|
||||
} else {
|
||||
console.log("Saving hash to local storage")
|
||||
hashFromLocalStorage.setData(hash)
|
||||
dedicatedHashFromLocalStorage.setData(hash)
|
||||
}
|
||||
|
||||
try {
|
||||
json = JSON.parse(atob(hash))
|
||||
} catch (e) {
|
||||
// We try to decode with lz-string
|
||||
json = JSON.parse(Utils.UnMinify(LZString.decompressFromBase64(hash)))
|
||||
}
|
||||
|
||||
json = await this.expandRemoteLayers(json)
|
||||
|
||||
const layoutToUse = DetermineTheme.prepCustomTheme(json)
|
||||
userLayoutParam.setData(layoutToUse.id)
|
||||
return layoutToUse
|
||||
}
|
||||
|
||||
private static getSharedTagRenderings(): Map<string, QuestionableTagRenderingConfigJson> {
|
||||
const dict = new Map<string, QuestionableTagRenderingConfigJson>()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue