work-graph-simple/app.js

73 lines
1.7 KiB
JavaScript

import * as FSHandle from "./store-directory-handle.js";
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 {(handle:boolean)=>Promise<void>} */
async function ReloadAndRedraw(handle)
{
if(handle)
{
const module = await import("./data/room.js");
const rooms = module.default();
button.innerText = "change directory";
listRoom.innerHTML = "";
Object.entries(rooms).forEach(([roomID, roomData])=>
{
const listPass = H("ul");
Object.entries(roomData.Pass).forEach(([passID, passData])=>{
listPass.appendChild(H("li", {},
H("button", { onclick(){ passData.load();console.log(roomData);globalThis.ROOM=roomData; } }, passData.name)
))
});
listRoom.appendChild(
H("li", {},
H("div", {}, roomID),
listPass
)
);
})
}
else
{
button.innerText = "select directory";
}
}
let handle = false;
handle = await FSHandle.getDirectoryHandle();
await ReloadAndRedraw(handle);
button.addEventListener("click", async()=>
{
const directory = await globalThis.showDirectoryPicker();
await FSHandle.setDirectoryHandle(directory);
handle = await FSHandle.getDirectoryHandle();
await ReloadAndRedraw(handle);
});
document.body.appendChild(button);
document.body.appendChild(listRoom);