Files
byre/web/dist/todolink.js
T

56 lines
2.5 KiB
JavaScript
Raw Normal View History

2026-10-15 20:20:02 -07:00
import { post } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { currentSession, focusTask, state } from "./state.js";
import { taskStyle } from "./taskcolor.js";
const starting = new Set();
export function todoLink(projectId, title, children) {
return h("span", { class: "todo-link", data: { project: projectId, title } }, h("span", { class: "todo-title" }, ...children), " ", h("span", { class: "todo-action" }));
}
export function fillTodoLinks(root, model) {
for (const el of root.querySelectorAll(".todo-link")) {
fill(el, model);
}
}
function fill(el, model) {
const projectId = el.dataset["project"];
const title = el.dataset["title"];
const action = el.querySelector(".todo-action");
const titleEl = el.querySelector(".todo-title");
const task = (state.tasks.get(projectId) ?? []).find((t) => t.status === "active" && t.todo_item === title);
if (task) {
const sess = currentSession(task.id);
el.setAttribute("style", taskStyle(task.id));
titleEl.classList.add("task-name");
replace(action, h("a", {
class: "todo-task",
href: `#/task/${task.id}`,
onclick: (e) => {
e.preventDefault();
focusTask(task.id);
},
}, h("span", { class: `dot ${sess?.state ?? "none"}`, title: sess?.state ?? "no session" }), sess?.state ?? "no agent"));
return;
}
el.removeAttribute("style");
titleEl.classList.remove("task-name");
const key = `${projectId}\n${title}`;
const busy = starting.has(key);
const start = async (discuss) => {
2026-10-15 20:20:02 -07:00
starting.add(key);
fill(el, model);
try {
await post("/api/projects/{projectId}/todo/tasks", { path: { projectId }, body: { title, model, discuss } });
2026-10-15 20:20:02 -07:00
}
catch (err) {
void showAlert(errorText(err));
}
starting.delete(key);
fill(el, model);
};
2026-10-16 09:16:40 -07:00
const startButton = h("button", { disabled: busy, title: "Start a task that gets straight to work" }, busy ? "starting…" : "start");
startButton.onclick = () => void start(false);
2026-10-16 09:16:40 -07:00
const discussButton = h("button", { disabled: busy, title: "Start a task that talks it through with you before changing anything" }, "discuss");
discussButton.onclick = () => void start(true);
2026-10-16 09:16:40 -07:00
replace(action, startButton, h("span", { class: "todo-sep" }, " · "), discussButton);
2026-10-15 20:20:02 -07:00
}
//# sourceMappingURL=todolink.js.map