Add dynamic loading of userLayout from localStorage
This commit is contained in:
parent
b4f95e5408
commit
58d6903ec5
3 changed files with 16 additions and 8 deletions
|
@ -3,10 +3,7 @@ import {UIEventSource} from "../UIEventSource";
|
||||||
export class LocalStorageSource {
|
export class LocalStorageSource {
|
||||||
|
|
||||||
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
const saved = localStorage.getItem(key);
|
const saved = localStorage.getItem(key);
|
||||||
const source = new UIEventSource<string>(saved ?? defaultValue);
|
const source = new UIEventSource<string>(saved ?? defaultValue);
|
||||||
|
|
||||||
|
|
|
@ -535,7 +535,7 @@ export class ThemeGenerator extends UIElement {
|
||||||
if (window.location.hostname === "127.0.0.1") {
|
if (window.location.hostname === "127.0.0.1") {
|
||||||
baseUrl = "http://127.0.0.1:1234";
|
baseUrl = "http://127.0.0.1:1234";
|
||||||
}
|
}
|
||||||
this.url = base64.map((data) => baseUrl + `/index.html?test=true&userlayout=true#` + data);
|
this.url = base64.map((data) => `${baseUrl}/index.html?test=true&userlayout=${this.themeObject.data.name}#${data}`);
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
pingThemeObject = () => {self.themeObject.ping()};
|
pingThemeObject = () => {self.themeObject.ping()};
|
||||||
|
|
19
index.ts
19
index.ts
|
@ -69,17 +69,28 @@ defaultLayout = QueryParameters.GetQueryParameter("layout", defaultLayout).data;
|
||||||
let layoutToUse: Layout = AllKnownLayouts.allSets[defaultLayout] ?? AllKnownLayouts["all"];
|
let layoutToUse: Layout = AllKnownLayouts.allSets[defaultLayout] ?? AllKnownLayouts["all"];
|
||||||
|
|
||||||
|
|
||||||
const layoutFromBase64 = QueryParameters.GetQueryParameter("userlayout", "false").data;
|
const userLayoutParam = QueryParameters.GetQueryParameter("userlayout", "false");
|
||||||
|
const layoutFromBase64 = userLayoutParam.data;
|
||||||
if (layoutFromBase64 !== "false") {
|
if (layoutFromBase64 !== "false") {
|
||||||
try {
|
try {
|
||||||
|
// layoutFromBase64 contains the name of the theme. This is partly to do tracking with goat counter
|
||||||
|
|
||||||
|
const dedicatedHashFromLocalStorage = LocalStorageSource.Get("user-layout-" + layoutFromBase64.replace(" ", "_"));
|
||||||
|
|
||||||
|
if(dedicatedHashFromLocalStorage.data?.length < 10){
|
||||||
|
dedicatedHashFromLocalStorage.setData(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
const hashFromLocalStorage = LocalStorageSource.Get("last-loaded-user-layout");
|
const hashFromLocalStorage = LocalStorageSource.Get("last-loaded-user-layout");
|
||||||
if(hash.length < 10){
|
if (hash.length < 10) {
|
||||||
hash = hashFromLocalStorage.data;
|
hash = dedicatedHashFromLocalStorage.data ?? hashFromLocalStorage.data;
|
||||||
}else{
|
} else {
|
||||||
console.log("Saving hash to local storage")
|
console.log("Saving hash to local storage")
|
||||||
hashFromLocalStorage.setData(hash);
|
hashFromLocalStorage.setData(hash);
|
||||||
|
dedicatedHashFromLocalStorage.setData(hash);
|
||||||
}
|
}
|
||||||
layoutToUse = CustomLayoutFromJSON.FromQueryParam(hash.substr(1));
|
layoutToUse = CustomLayoutFromJSON.FromQueryParam(hash.substr(1));
|
||||||
|
userLayoutParam.setData(layoutToUse.name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
new FixedUiElement("Error: could not parse the custom layout:<br/> "+e).AttachTo("centermessage");
|
new FixedUiElement("Error: could not parse the custom layout:<br/> "+e).AttachTo("centermessage");
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in a new issue