diff --git a/package.json b/package.json index 7d04326..a68a545 100644 --- a/package.json +++ b/package.json @@ -9,15 +9,7 @@ "lint": "eslint src", "build": "vite build --base=./" }, - "dependencies": { - "@types/node": "^20.12.7", - "@types/service_worker_api": "^0.0.9", - "prettier": "^3.2.5", - "sass": "^1.75.0", - "typescript": "^5.4.5", - "vite": "^5.2.10", - "vite-plugin-pwa": "^0.19.8" - }, + "dependencies": {}, "browserslist": [ "last 2 Chrome versions", "last 2 Firefox versions" @@ -30,13 +22,21 @@ "runtimeCaching": [ { "urlPattern": [ - "i" + "i", + "" ], "handler": "cacheFirst" } ] }, "devDependencies": { + "@types/node": "^20.12.7", + "@types/service_worker_api": "^0.0.9", + "prettier": "^3.2.5", + "sass": "^1.75.0", + "typescript": "^5.4.5", + "vite": "^5.2.10", + "vite-plugin-pwa": "^0.19.8", "@eslint/js": "^9.1.1", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", diff --git a/src/index.ts b/src/index.ts index bac0d81..73a415a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,12 +4,6 @@ import { nextAnimationFrame } from "./utils.ts"; import { gotoPage, searchBox } from "./scripts/search.ts"; import { getCurrentPage } from "./scripts/history.ts"; -import unknown from "@assets/images/tab-icons/unknown.svg"; - -// Enable single page mode for developing scripts -// const devSinglePage = ["Medical", "Infections"]; -const devSinglePage = null; - async function load() { const sectionListContainer = document.getElementById("section-list")!; const tabListContainer = document.getElementById("tab-list")!; @@ -21,57 +15,27 @@ async function load() { ); manager.setLoading(true); - // De-comment to disable caching and force processing - // manager.cacheEnabled = false; - await nextAnimationFrame(); - // Add loading "bar" - const spinnerContainer = document.querySelector("#tabs > .speen")!; - const icons = document.createElement("div"); - icons.className = "loading-icons"; - - let promises: Promise[] = []; - if (devSinglePage != null) { - manager.createSection(devSinglePage[0]); - promises = [manager.openTab(devSinglePage[0], devSinglePage[1], {})]; - } else { - sections.forEach((section) => - section.tabs.forEach((tab) => { - const iconElement = document.createElement("img"); - iconElement.dataset.tab = tab.page; - iconElement.src = tab.icon || unknown; - iconElement.title = tab.page.replace(/_/gi, " "); - icons.appendChild(iconElement); - }), - ); - spinnerContainer.appendChild(icons); + const promises = sections.flatMap((section) => { + manager.createSection(section.name); - promises = sections.flatMap((section) => { - manager.createSection(section.name); - - return section.tabs.map(async (tab) => { - // Load page - await manager.openTab(section.name, tab, {}); - // Remove icon from loading - icons.querySelector(`img[data-tab="${tab.page}"]`)?.remove(); - }); + return section.tabs.map(async (tab) => { + // Load page + await manager.openTab(section.name, tab, {}); }); - } + }); Promise.all(promises).then(() => { // Remove app-wide loading manager.setLoading(false); - if (devSinglePage) { - manager.setActive(devSinglePage[1]); - } else { - const { path, hash } = getCurrentPage(); - // Try to open page from URL, open landing page if fail - if (!gotoPage(path, hash)) { - manager.setActive("$Welcome"); - manager.showSection("Medical"); - } + const { path, hash } = getCurrentPage(); + + // Try to open page from URL, open landing page if fail + if (!gotoPage(path, hash)) { + manager.setActive("$Welcome"); + manager.showSection("Medical"); } }); }