From 4faccb4785b62222d34f95928f458d7cab1a6402 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Thu, 30 Oct 2025 17:12:42 -0400 Subject: [PATCH] tweaks --- app-gale.js | 30 ++++++++---- app-original.js | 121 ------------------------------------------------ graph/graph.js | 1 - 3 files changed, 22 insertions(+), 130 deletions(-) delete mode 100644 app-original.js diff --git a/app-gale.js b/app-gale.js index bc18864..e5e1300 100644 --- a/app-gale.js +++ b/app-gale.js @@ -32,15 +32,29 @@ async function EvaluateHandle() let handle = await FSHandle.getDirectoryHandle(); EvaluateHandle(); -/** @type {(pass:TYPES.Pass)=>HTMLElement} */ -function Pass(pass) +/** @type {(pass:TYPES.Pass, parts:TYPES.GraphParts)=>()=>HTMLElement} */ +function Pass(pass, parts) { - return Div.Plain( - Div.Title( - DOM.span.Plain(pass.name), - DOM.span.Plain(pass.path), + const rerender = van.state(0); + return ()=>{ + console.log("rerendering...", rerender.val) + return Div.Plain( + Div.Title( + DOM.div.Plain(pass.name), + DOM.span.Plain(pass.path), + ), + ()=>{ + return DOM.button.Plain( + {async onclick(){ + await pass.load(); + rerender.val++ + }}, + pass.live ? "Dump" : "Load" + ) + }, + ) - ) + } } @@ -56,7 +70,7 @@ function App() }, "Pick Directory"), Object.entries(rooms.val).map(([room_id, graphParts])=> Object.entries(graphParts.Pass).map(([pass_id, pass])=>{ - return Pass(pass) + return Pass(pass, graphParts) }) ) ) diff --git a/app-original.js b/app-original.js deleted file mode 100644 index 43db91a..0000000 --- a/app-original.js +++ /dev/null @@ -1,121 +0,0 @@ -/** @import * as TYPES from "./graph/types.ts" */ - -import * as FSHandle from "./store-directory-handle.js"; - - -/** @type {(type:string, attributes?:Record, ...children:Array)=>HTMLElement} */ -const H =(type, attributes={}, ...children)=> { - const el =document.createElement(type); - Object.entries(attributes).forEach(([name, data])=>{ - if(name.startsWith("on")) - { - el.addEventListener(name.substring(2), data); - } - else - { - el.setAttribute(name, data) - } - - }); - - children.forEach(child=> - { - el.appendChild(typeof child == "string" ? document.createTextNode(child) : child); - }); - return el; -} -const button = H("button"); -const listRoom = H("ul"); - -/** @type {(errorAction?:()=>void)=>Promise} */ -async function ReloadAndRedraw(errorAction = ()=>{}) -{ - listRoom.innerHTML = ""; - - try - { - const handle = await FSHandle.getDirectoryHandle(); - if(!handle) - { - console.log("no fs handle") - throw new Error("no fs handle set yet") - } - button.setAttribute("disabled", true); - button.innerText = "loading..."; - - const module = await import("./data/room.js"+"?rand="+Math.random()); - /** @type {Record} */ - const rooms = module.default(); - button.innerText = "change directory"; - console.log("rooms loaded:", rooms); - - Redraw(rooms); - - } - catch(e) - { - errorAction(); - button.innerText = "select directory"; - } - button.removeAttribute("disabled") -} - - -function Redraw(rooms) -{ - Object.entries(rooms).forEach(([roomID, roomData])=> - { - const listPass = H("ul"); - Object.entries(roomData.Pass).forEach(([passID, passData])=>{ - - listPass.appendChild(H("li", {}, - H("button", { onclick:async()=> - { - await passData.load(); - globalThis.ROOM=roomData; - Redraw(rooms) - } }, passData.name), - )) - }); - - - const listPart = H("ul"); - Object.entries(roomData.Part).forEach(([partId, partData])=>{ - - const listWork = H("dl"); - - partData.pass.entries().forEach(([pass, passMapper])=>{ - listWork.appendChild(H("dt", {}, pass.name)) - passMapper.work.forEach((w)=>{ - listWork.appendChild(H("dd", {}, w.join(" "))) - }) - }) - - listPart.appendChild(H("li", {}, - H("h2", {}, partData.name), - listWork - )); - }) - - listRoom.innerHTML = ""; - listRoom.appendChild( - H("li", {}, - H("div", {}, roomID), - listPass, - H("div", {}, listPart) - ) - ); - }) -} - -await ReloadAndRedraw(); - -button.addEventListener("click", async()=> -{ - const directory = await globalThis.showDirectoryPicker(); - await FSHandle.setDirectoryHandle(directory); - await ReloadAndRedraw(()=>alert("Invalid directory")); -}); - -document.body.appendChild(button); -document.body.appendChild(listRoom); \ No newline at end of file diff --git a/graph/graph.js b/graph/graph.js index c4b6459..d868535 100644 --- a/graph/graph.js +++ b/graph/graph.js @@ -92,7 +92,6 @@ function Builder({user, role, part, desk, pass}, folderName) path:passID, async load(){ - // make room for this pass to each part and desk Object.values(PartList).forEach((partObj)=> {