writing works

This commit is contained in:
Seth Trowbridge 2025-11-01 08:23:28 -04:00
parent 7a54689f76
commit 5ac0b07bd7
3 changed files with 23 additions and 6 deletions

7
app.js
View File

@ -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

View File

@ -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)});

View File

@ -76,7 +76,7 @@ export async function Read(handle, parts)
/** @type {(handle:FileSystemDirectoryHandle, parts:string[], text:string)=>Promise<boolean>} */
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();