Move the window global in settings.ts to Alu.settings
This commit is contained in:
parent
255488ad16
commit
0765072ea2
6 changed files with 17 additions and 15 deletions
5
src/alu.d.ts
vendored
5
src/alu.d.ts
vendored
|
|
@ -1,7 +1,10 @@
|
||||||
export declare global {
|
export declare global {
|
||||||
namespace Alu {
|
namespace Alu {
|
||||||
let store: AluStore;
|
let store: AluStore;
|
||||||
let loadedContentStorage: Record<string, string>;
|
let settings: {
|
||||||
|
loadedContentStorage: Record<string, string>;
|
||||||
|
currentTab: string;
|
||||||
|
};
|
||||||
|
|
||||||
type DefaultKeys = {
|
type DefaultKeys = {
|
||||||
[key: string]: AluKey;
|
[key: string]: AluKey;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ function instantiateAlu() {
|
||||||
if (globalThis.Alu) return;
|
if (globalThis.Alu) return;
|
||||||
globalThis.Alu = {
|
globalThis.Alu = {
|
||||||
store: new AluStore(),
|
store: new AluStore(),
|
||||||
|
settings: {
|
||||||
loadedContentStorage: {},
|
loadedContentStorage: {},
|
||||||
|
currentTab: "",
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
window.loadedContentStorage = {};
|
// Alu.settings.loadedContentStorage = {};
|
||||||
window.currentlySelectedTab;
|
|
||||||
document.addEventListener("astro:before-swap", () => {
|
document.addEventListener("astro:before-swap", () => {
|
||||||
window.currentlySelectedTab = "";
|
Alu.settings.currentTab = "";
|
||||||
|
Alu.settings.loadedContentStorage = {};
|
||||||
});
|
});
|
||||||
function settingsLoad() {
|
function settingsLoad() {
|
||||||
Array.from(document.getElementsByClassName("setting-tab")).forEach((tab) => {
|
Array.from(document.getElementsByClassName("setting-tab")).forEach((tab) => {
|
||||||
const contentToLoad = document.getElementById("content-" + tab.id);
|
const contentToLoad = document.getElementById("content-" + tab.id);
|
||||||
if (contentToLoad) {
|
if (contentToLoad) {
|
||||||
window.loadedContentStorage[tab.id] = contentToLoad.innerHTML;
|
Alu.settings.loadedContentStorage[tab.id] = contentToLoad.innerHTML;
|
||||||
contentToLoad.remove();
|
contentToLoad.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,13 +18,13 @@ function settingsLoad() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function loadContent(tabID: string) {
|
function loadContent(tabID: string) {
|
||||||
if (window.currentlySelectedTab == tabID) return;
|
if (Alu.settings.currentTab == tabID) return;
|
||||||
else window.currentlySelectedTab = tabID;
|
else Alu.settings.currentTab = tabID;
|
||||||
const currentContent = document.getElementById("current-content");
|
const currentContent = document.getElementById("current-content");
|
||||||
if (currentContent) {
|
if (currentContent) {
|
||||||
currentContent.style.opacity = "0";
|
currentContent.style.opacity = "0";
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
currentContent.innerHTML = window.loadedContentStorage[tabID];
|
currentContent.innerHTML = Alu.settings.loadedContentStorage[tabID];
|
||||||
currentContent.style.opacity = "1";
|
currentContent.style.opacity = "1";
|
||||||
document.dispatchEvent(new CustomEvent("setting-tabLoad", { detail: tabID }));
|
document.dispatchEvent(new CustomEvent("setting-tabLoad", { detail: tabID }));
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
@ -84,7 +84,6 @@ function getLocalStorageValue(localStorageItem: Alu.ValidStoreKeys, dropdownID:
|
||||||
const dropdownMenu = document.getElementById(dropdownID + "-menu") as HTMLElement;
|
const dropdownMenu = document.getElementById(dropdownID + "-menu") as HTMLElement;
|
||||||
// Janky hack :D
|
// Janky hack :D
|
||||||
if (dropdownID == "dropdown__search-engine") {
|
if (dropdownID == "dropdown__search-engine") {
|
||||||
console.log(localStorageItem, dropdownID)
|
|
||||||
return Alu.store.get(localStorageItem).name;
|
return Alu.store.get(localStorageItem).name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ export function getStaticPaths() {
|
||||||
game.style.display = "none";
|
game.style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(results);
|
|
||||||
if (results === 0) {
|
if (results === 0) {
|
||||||
const noResults = document.querySelector(".no-results") as HTMLDivElement;
|
const noResults = document.querySelector(".no-results") as HTMLDivElement;
|
||||||
if (noResults) {
|
if (noResults) {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
gtag("config", "G-P1JX4G9KSF");
|
gtag("config", "G-P1JX4G9KSF");
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
import instantiateAlu from "@components/ts/Alu";
|
||||||
|
instantiateAlu();
|
||||||
const lang = Alu.store.get("lang");
|
const lang = Alu.store.get("lang");
|
||||||
const redirect = (loc: string) => (window.location.href = loc);
|
const redirect = (loc: string) => (window.location.href = loc);
|
||||||
if (lang) {
|
if (lang) {
|
||||||
|
|
|
||||||
4
src/types.d.ts
vendored
4
src/types.d.ts
vendored
|
|
@ -8,11 +8,7 @@ interface Window {
|
||||||
__uv$location: Location;
|
__uv$location: Location;
|
||||||
loadFormContent: () => Promise<void> | null;
|
loadFormContent: () => Promise<void> | null;
|
||||||
idb: IDBDatabase;
|
idb: IDBDatabase;
|
||||||
// Why is this not already on Window?
|
|
||||||
eval(string): void;
|
|
||||||
wispData: WispData[];
|
wispData: WispData[];
|
||||||
loadedContentStorage: Record<string, string>;
|
|
||||||
currentlySelectedTab: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExtType = "serviceWorker" | "theme" | "page";
|
type ExtType = "serviceWorker" | "theme" | "page";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue