Files
byre/web/dist/app.js
T

92 lines
3.5 KiB
JavaScript
Raw Normal View History

import { get, put, subscribe } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { leadPane, taskPane } from "./panes.js";
import { handleEvent, loadFocus, loadInbox, loadLeadSessions, loadMe, loadProjects, notify, on, selectTask, setFocus, startLeadStream, state, tabs } from "./state.js";
2026-10-15 22:21:20 -07:00
import { bindShortcuts } from "./switcher.js";
function identityBanner(root) {
const render = () => {
const me = state.me;
if (!me || (me.git_name && me.git_email)) {
replace(root);
root.hidden = true;
return;
}
const name = h("input", { placeholder: "Git name", value: me.display_name, required: true });
const email = h("input", { type: "email", placeholder: "Git email", required: true });
const form = h("form", { class: "inline-form" }, "Set the identity agents commit as: ", name, email, h("button", { type: "submit" }, "Save"));
form.onsubmit = async (e) => {
e.preventDefault();
try {
state.me = await put("/api/me", { body: { git_name: name.value, git_email: email.value } });
render();
}
catch (err) {
void showAlert(errorText(err));
}
};
root.hidden = false;
replace(root, form);
};
on("me", render);
render();
}
function route() {
const match = /^#\/(task|project)\/(\w+)(?:\/(\w+))?$/.exec(location.hash);
const taskId = match?.[1] === "task" ? match[2] : undefined;
const projectId = match?.[1] === "project" ? match[2] : undefined;
const tab = tabs.find((t) => t === match?.[3]);
if (taskId) {
if (taskId !== state.focus.task_id || (tab && tab !== state.focus.tab)) {
setFocus({ task_id: taskId, tab }).catch((err) => console.error("set focus", err));
}
}
else if (state.focus.task_id || projectId !== state.focus.project_id) {
setFocus({ task_id: null, project_id: projectId ?? null }).catch((err) => console.error("set focus", err));
}
if (taskId !== state.selectedTaskId) {
selectTask(taskId);
}
}
async function main() {
const banner = h("div", { class: "banner", hidden: true });
const status = await get("/api/admin/status");
await Promise.all([loadMe(), loadProjects(), loadInbox(), loadLeadSessions()]);
const linked = location.hash;
await loadFocus();
if (/^#\/(task|project)\/\w+(\/\w+)?$/.test(linked)) {
location.hash = linked;
}
startLeadStream();
2026-10-15 22:21:20 -07:00
replace(document.body, banner, h("div", { class: "panes" }, leadPane(), taskPane()));
bindShortcuts();
identityBanner(banner);
addEventListener("keydown", (e) => {
if (e.key !== "Escape") {
return;
}
e.preventDefault();
document.querySelector("dialog[open]")?.close();
}, { capture: true });
subscribe(status.last_event_seq, {}, handleEvent, (connected) => {
state.connected = connected;
notify("connection");
});
addEventListener("hashchange", route);
route();
}
async function start() {
if ("serviceWorker" in navigator) {
for (const reg of await navigator.serviceWorker.getRegistrations()) {
await reg.unregister();
}
if (navigator.serviceWorker.controller) {
location.reload();
return;
}
}
await main();
}
start().catch((err) => {
replace(document.body, h("pre", { class: "fatal" }, `byre failed to start: ${errorText(err)}`));
});
//# sourceMappingURL=app.js.map