diff --git a/app.js b/app.js index d92d895..5fb88ab 100644 --- a/app.js +++ b/app.js @@ -162,12 +162,11 @@ function Room(room_id, graphParts) DOM.strong(data), )), Div.Plain( - loggedIn.val ? DOM.button({onclick(){ + loggedIn.val ? DOM.button({async onclick(){ if(loggedIn.val) { - data.make(loggedIn.val, "NEW"); - rerender.val++ - WRITE(["room", room_id, pass.id, loggedIn.val.id+".json"], part_id, new Date().getTime(), "NEW"); + await data.make(loggedIn.val, "NEW"); + rerender.val++; } }}, "Add work!") : null diff --git a/graph/graph.js b/graph/graph.js index 09feb90..81ba8cb 100644 --- a/graph/graph.js +++ b/graph/graph.js @@ -99,9 +99,27 @@ export function Room({user, role, part, desk, pass}) // make room for this pass to each part and desk Object.values(PartList).forEach((partObj)=> { - partObj.pass.set(passObj, {time:0, work:[], make(user, data) + partObj.pass.set(passObj, {time:0, work:[], async make(user, data) { this.time = Date.now(); + + const handle = await FSAccess.getDirectoryHandle(); + const path = ["store", context.Path, passID, user.id+".json"]; + let text = await FSAccess.Read(handle, path) || "{}"; + console.log("json loaded", text); + /** @type {TYPES.UserPassFile} */ + const json = JSON.parse(text); + + let field = json[partObj.id]; + if(!field) + { + field = []; + json[partObj.id] = field; + } + field.push([this.time, data]); + text = JSON.stringify(json, null, 2); + await FSAccess.Write(handle, path, text); + this.work.push(/** @type {TYPES.Work}*/([this.time, data, user])); partObj.make.forEach((arg)=>{Scan(arg, passObj)}); partObj.need.forEach((arg)=>{Scan(arg, passObj)}); diff --git a/store-directory-handle.js b/store-directory-handle.js index cfe8a06..74d7e71 100644 --- a/store-directory-handle.js +++ b/store-directory-handle.js @@ -76,7 +76,7 @@ export async function Read(handle, parts) /** @type {(handle:FileSystemDirectoryHandle, parts:string[], text:string)=>Promise} */ export async function Write(handle, parts, text) { - const fileHandle = await Dig(handle, parts); + const fileHandle = await Dig(handle, parts, true); if(fileHandle) { const writeable = await fileHandle.createWritable();