Let the lead keep notes on how its user works

This commit is contained in:
Ian Gulliver
2026-10-16 10:50:29 -07:00
parent 919e1f8002
commit d6f73a1560
18 changed files with 759 additions and 208 deletions
+54 -5
View File
@@ -1,5 +1,5 @@
import { put } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { del, get, put } from "./api.js";
import { errorText, h, replace, showAlert, showConfirm } from "./dom.js";
import { on, state } from "./state.js";
const kinds = [
{ key: "questions", label: "Questions" },
@@ -51,10 +51,59 @@ export function mountSettings(root) {
};
replace(device, h("p", {}, "This browser doesn't show notifications."), button);
};
replace(root, h("div", { class: "settings-view" }, h("h2", {}, "Notifications"), device, prefs));
const off = on("me", renderPrefs);
const notes = h("div", { class: "lead-notes" });
let loads = 0;
const loadNotes = async () => {
const n = ++loads;
let list;
try {
list = await get("/api/me/lead/notes");
}
catch (err) {
replace(notes, h("p", { class: "hint" }, errorText(err)));
return;
}
if (n !== loads) {
return;
}
if (list.length === 0) {
replace(notes, h("p", { class: "hint" }, "Your lead hasn't noted anything about how you work yet."));
return;
}
replace(notes, h("ul", {}, ...list.map((note) => {
const remove = h("button", {}, "delete");
remove.onclick = async () => {
if (!(await showConfirm([h("p", {}, "Delete this note? Your lead stops applying it."), h("p", {}, note.text)], "Delete", true, remove))) {
return;
}
try {
await del("/api/me/lead/notes/{noteId}", { path: { noteId: note.id } });
}
catch (err) {
void showAlert(errorText(err));
}
};
return h("li", {}, h("span", {}, note.text), remove);
})));
};
replace(root, h("div", { class: "settings-view" }, h("h2", {}, "Notifications"), device, prefs, h("h2", {}, "What your lead has learned"), h("p", { class: "hint" }, "Your lead notes your priorities and preferences as it works with you, and starts every session with them."), notes));
const offs = [
on("me", renderPrefs),
on("event", (detail) => {
const ev = detail;
if (ev.kind === "lead.note_saved" || ev.kind === "lead.note_deleted") {
void loadNotes();
}
}),
];
renderPrefs();
renderDevice();
return off;
void loadNotes();
return () => {
loads++;
for (const off of offs) {
off();
}
};
}
//# sourceMappingURL=settings.js.map