From 6c3b8b202020dc4ea14d13822dac07bce5931400 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 17 Jun 2021 00:37:57 +0200 Subject: [PATCH] Fix loading of the hash of a custom theme, even if the custom theme is not loaded via the URL. Fixes 352 --- InitUiElements.ts | 4 ++-- index.ts | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index cb7cdc5623..a5b738e9ca 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -215,7 +215,7 @@ export class InitUiElements { } - static LoadLayoutFromHash(userLayoutParam: UIEventSource) { + static LoadLayoutFromHash(userLayoutParam: UIEventSource): [LayoutConfig, string]{ try { let hash = location.hash.substr(1); const layoutFromBase64 = userLayoutParam.data; @@ -247,7 +247,7 @@ export class InitUiElements { // @ts-ignore const layoutToUse = new LayoutConfig(json, false); userLayoutParam.setData(layoutToUse.id); - return layoutToUse; + return [layoutToUse, btoa(Utils.MinifyJSON(JSON.stringify(json)))]; } catch (e) { new FixedUiElement("Error: could not parse the custom layout:
" + e).AttachTo("centermessage"); diff --git a/index.ts b/index.ts index 79a81b2ea0..472fb943fb 100644 --- a/index.ts +++ b/index.ts @@ -5,7 +5,6 @@ import {QueryParameters} from "./Logic/Web/QueryParameters"; import {UIEventSource} from "./Logic/UIEventSource"; import * as $ from "jquery"; import LayoutConfig from "./Customizations/JSON/LayoutConfig"; -import {Utils} from "./Utils"; import MoreScreen from "./UI/BigComponents/MoreScreen"; import State from "./State"; import Combine from "./UI/Base/Combine"; @@ -34,7 +33,6 @@ if (location.href.indexOf("buurtnatuur.be") >= 0) { } - let testing: UIEventSource; if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { testing = QueryParameters.GetQueryParameter("test", "true"); @@ -88,7 +86,7 @@ new Combine(["Initializing...
", new FixedUiElement("If this message persist, something went wrong - click here to try again") .SetClass("link-underline small") .onClick(() => { - localStorage.clear(); + localStorage.clear(); window.location.reload(true); })]) @@ -136,8 +134,8 @@ if (layoutFromBase64.startsWith("http")) { }); } else if (layoutFromBase64 !== "false") { - layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam); - InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout, location.hash.substr(1)); + let [layoutToUse, encoded] = InitUiElements.LoadLayoutFromHash(userLayoutParam); + InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout, encoded); } else if (layoutToUse !== undefined) { // This is the default case: a builtin theme InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);