2026-10-15 09:59:13 -07:00
|
|
|
import { put, type TaskTab } from "./api.js";
|
2026-10-14 19:35:34 -07:00
|
|
|
import { mountChanges } from "./changes.js";
|
2026-10-14 09:40:12 -07:00
|
|
|
import { h, replace } from "./dom.js";
|
2026-10-15 07:31:53 -07:00
|
|
|
import { mountFiles } from "./files.js";
|
2026-10-14 09:40:12 -07:00
|
|
|
import { mountInbox } from "./inbox.js";
|
2026-10-15 09:40:30 -07:00
|
|
|
import { mountLead } from "./lead.js";
|
2026-10-15 12:03:01 -07:00
|
|
|
import { openSwitcher } from "./navbar.js";
|
|
|
|
|
import { findTask, focusedProject, focusTab, on, onEach, state, tabs } from "./state.js";
|
2026-10-15 13:15:49 -07:00
|
|
|
import { mountPreview } from "./preview.js";
|
2026-10-15 10:36:32 -07:00
|
|
|
import { mountProject } from "./project.js";
|
2026-10-15 17:49:59 -07:00
|
|
|
import { isReviewEvent, mountReviews } from "./reviews.js";
|
2026-10-15 13:49:10 -07:00
|
|
|
import { mountTranscript } from "./task.js";
|
|
|
|
|
import { mountTerminal } from "./terminal.js";
|
2026-10-14 09:40:12 -07:00
|
|
|
|
2026-10-15 09:40:30 -07:00
|
|
|
const views: Record<TaskTab, { label: string; mount: (root: HTMLElement) => () => void }> = {
|
2026-10-14 09:40:12 -07:00
|
|
|
transcript: { label: "Transcript", mount: mountTranscript },
|
2026-10-14 19:35:34 -07:00
|
|
|
changes: { label: "Changes", mount: (root) => mountChanges(root) },
|
2026-10-15 07:31:53 -07:00
|
|
|
files: { label: "Files", mount: mountFiles },
|
2026-10-15 12:06:50 -07:00
|
|
|
terminal: { label: "Terminal", mount: mountTerminal },
|
2026-10-15 13:15:49 -07:00
|
|
|
preview: { label: "Preview", mount: mountPreview },
|
2026-10-14 09:40:12 -07:00
|
|
|
inbox: { label: "Inbox", mount: mountInbox },
|
2026-10-15 16:33:17 -07:00
|
|
|
reviews: { label: "Reviews", mount: mountReviews },
|
2026-10-15 10:36:32 -07:00
|
|
|
project: { label: "Project", mount: mountProject },
|
2026-10-14 09:40:12 -07:00
|
|
|
};
|
|
|
|
|
|
2026-10-15 09:40:30 -07:00
|
|
|
export function leadPane(): HTMLElement {
|
|
|
|
|
const root = h("div", { class: "view view-lead" });
|
|
|
|
|
mountLead(root);
|
|
|
|
|
return h("section", { class: "pane" }, h("nav", { class: "pane-tabs" }, h("button", { class: "active" }, "Lead")), h("div", { class: "pane-body" }, root));
|
2026-10-15 00:08:32 -07:00
|
|
|
}
|
|
|
|
|
|
2026-10-15 09:40:30 -07:00
|
|
|
export function taskPane(): HTMLElement {
|
|
|
|
|
const strip = h("nav", { class: "pane-tabs" });
|
|
|
|
|
const body = h("div", { class: "pane-body" });
|
2026-10-15 12:03:01 -07:00
|
|
|
const picker = h("button", { class: "task-picker", title: "Switch task (⌘K)" });
|
|
|
|
|
picker.onclick = openSwitcher;
|
2026-10-15 13:30:09 -07:00
|
|
|
const pane = h("section", { class: "pane task-pane", tabIndex: -1 }, strip, body);
|
2026-10-15 09:40:30 -07:00
|
|
|
let shown: TaskTab | undefined;
|
|
|
|
|
let dispose: () => void = () => {};
|
2026-10-14 09:40:12 -07:00
|
|
|
|
2026-10-15 12:03:01 -07:00
|
|
|
const renderPicker = () => {
|
|
|
|
|
const task = state.selectedTaskId ? findTask(state.selectedTaskId) : undefined;
|
|
|
|
|
const project = focusedProject();
|
2026-10-15 13:30:09 -07:00
|
|
|
if (task) {
|
|
|
|
|
pane.style.setProperty("--task", `var(--task-${task.color})`);
|
|
|
|
|
} else {
|
|
|
|
|
pane.style.removeProperty("--task");
|
|
|
|
|
}
|
2026-10-15 12:03:01 -07:00
|
|
|
replace(picker, task ? `${project?.name ?? ""} ▸ ${task.title}` : (project?.name ?? "No task"), " ▾");
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-15 17:49:59 -07:00
|
|
|
const more = h("button", { type: "button", class: "more", title: "More tabs" });
|
|
|
|
|
const menu = h("div", { class: "tab-menu", popover: "auto" });
|
|
|
|
|
more.onclick = () => {
|
|
|
|
|
const rect = more.getBoundingClientRect();
|
|
|
|
|
menu.style.top = `${rect.bottom + 4}px`;
|
|
|
|
|
menu.style.left = `${rect.left}px`;
|
|
|
|
|
menu.togglePopover();
|
|
|
|
|
};
|
|
|
|
|
let buttons: { tab: TaskTab; button: HTMLButtonElement }[] = [];
|
|
|
|
|
let drawn = "";
|
|
|
|
|
let waiting = 0;
|
|
|
|
|
|
|
|
|
|
const layout = () => {
|
|
|
|
|
for (const { button } of buttons) {
|
|
|
|
|
button.hidden = false;
|
|
|
|
|
}
|
|
|
|
|
more.hidden = true;
|
|
|
|
|
const style = getComputedStyle(strip);
|
|
|
|
|
const gap = parseFloat(style.columnGap) || 0;
|
|
|
|
|
const inner = strip.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
|
|
|
const pickerWidth = Math.min(picker.scrollWidth, inner * 0.4);
|
|
|
|
|
const widths = new Map(buttons.map(({ tab, button }) => [tab, button.offsetWidth]));
|
|
|
|
|
const total = (kept: TaskTab[]) => kept.reduce((sum, t) => sum + widths.get(t)! + gap, 0);
|
|
|
|
|
const all = buttons.map((b) => b.tab);
|
|
|
|
|
let kept = all;
|
|
|
|
|
if (total(all) + gap + pickerWidth > inner) {
|
|
|
|
|
more.hidden = false;
|
|
|
|
|
const budget = inner - pickerWidth - more.offsetWidth - 2 * gap;
|
|
|
|
|
const tab = state.focus.tab;
|
|
|
|
|
kept = [];
|
|
|
|
|
for (const t of [tab, ...all.filter((t) => t !== tab)]) {
|
|
|
|
|
if (kept.length > 0 && total([...kept, t]) > budget) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
kept.push(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const hidden = all.filter((t) => !kept.includes(t));
|
|
|
|
|
for (const { tab, button } of buttons) {
|
|
|
|
|
button.hidden = hidden.includes(tab);
|
|
|
|
|
}
|
|
|
|
|
const attention = hidden.includes("inbox");
|
|
|
|
|
more.classList.toggle("attention", attention);
|
|
|
|
|
replace(more, "More ▾", attention && h("span", { class: "badge", title: "inbox items" }, waiting));
|
|
|
|
|
replace(
|
|
|
|
|
menu,
|
|
|
|
|
...hidden.map((t) => {
|
|
|
|
|
const b = h("button", { type: "button" }, views[t].label, t === "inbox" && h("span", { class: "badge", title: "inbox items" }, waiting));
|
|
|
|
|
b.onclick = () => {
|
|
|
|
|
menu.hidePopover();
|
|
|
|
|
focusTab(t);
|
|
|
|
|
};
|
|
|
|
|
return b;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const available = (t: TaskTab): boolean => {
|
|
|
|
|
if (t === state.focus.tab) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
switch (t) {
|
|
|
|
|
case "inbox":
|
|
|
|
|
return waiting > 0;
|
|
|
|
|
case "preview":
|
|
|
|
|
return state.transcript.some((ev) => ev.kind === "preview.exposed");
|
|
|
|
|
case "reviews":
|
|
|
|
|
return state.transcript.some(isReviewEvent);
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-15 09:40:30 -07:00
|
|
|
const render = () => {
|
|
|
|
|
const first = state.focus.tabs.filter((t, i, all) => tabs.includes(t) && all.indexOf(t) === i);
|
|
|
|
|
const tab = state.focus.tab;
|
2026-10-15 17:49:59 -07:00
|
|
|
waiting = state.inbox.filter((item) => item.task_id === state.selectedTaskId).length;
|
|
|
|
|
const order = [...first, ...tabs.filter((t) => !first.includes(t))].filter(available);
|
|
|
|
|
const key = JSON.stringify([order, tab, waiting]);
|
|
|
|
|
if (key !== drawn) {
|
|
|
|
|
drawn = key;
|
|
|
|
|
buttons = order.map((t) => {
|
2026-10-15 12:29:15 -07:00
|
|
|
const attention = t === "inbox" && waiting > 0;
|
2026-10-15 17:49:59 -07:00
|
|
|
const button = h(
|
2026-10-15 12:29:15 -07:00
|
|
|
"button",
|
|
|
|
|
{ class: [t === tab ? "active" : "", attention ? "attention" : ""].join(" ").trim() },
|
|
|
|
|
views[t].label,
|
|
|
|
|
attention && h("span", { class: "badge", title: "inbox items" }, waiting),
|
|
|
|
|
);
|
2026-10-15 17:49:59 -07:00
|
|
|
button.onclick = () => focusTab(t);
|
|
|
|
|
return { tab: t, button };
|
|
|
|
|
});
|
|
|
|
|
replace(strip, ...buttons.map((b) => b.button), more, h("span", { class: "spacer" }), picker, menu);
|
|
|
|
|
layout();
|
|
|
|
|
}
|
2026-10-15 09:40:30 -07:00
|
|
|
if (tab === shown) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dispose();
|
|
|
|
|
shown = tab;
|
|
|
|
|
const root = h("div", { class: `view view-${tab}` });
|
|
|
|
|
replace(body, root);
|
|
|
|
|
dispose = views[tab].mount(root);
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-15 18:24:49 -07:00
|
|
|
const seen = new Set(state.inbox.map((item) => item.id));
|
|
|
|
|
const openAsked = () => {
|
|
|
|
|
const fresh = state.inbox.filter((item) => !seen.has(item.id));
|
|
|
|
|
for (const item of fresh) {
|
|
|
|
|
seen.add(item.id);
|
|
|
|
|
}
|
|
|
|
|
if (state.focus.tab === "transcript" && fresh.some((item) => item.kind === "question" && item.task_id === state.selectedTaskId)) {
|
|
|
|
|
focusTab("inbox");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
on("inbox", openAsked);
|
2026-10-15 17:49:59 -07:00
|
|
|
onEach(["focus", "inbox", "selection", "transcript"], render);
|
|
|
|
|
onEach(["projects", "tasks", "selection", "focus"], () => {
|
|
|
|
|
renderPicker();
|
|
|
|
|
layout();
|
|
|
|
|
});
|
|
|
|
|
new ResizeObserver(layout).observe(strip);
|
2026-10-15 09:40:30 -07:00
|
|
|
render();
|
2026-10-15 12:03:01 -07:00
|
|
|
renderPicker();
|
2026-10-15 17:49:59 -07:00
|
|
|
layout();
|
2026-10-15 09:59:13 -07:00
|
|
|
trackPaneFocus(pane);
|
|
|
|
|
return pane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function trackPaneFocus(pane: HTMLElement): void {
|
|
|
|
|
let focused = false;
|
|
|
|
|
let inside: Element | null = null;
|
|
|
|
|
let sending: Promise<unknown> = Promise.resolve();
|
|
|
|
|
const send = () => {
|
|
|
|
|
const body = { focused };
|
|
|
|
|
sending = sending.then(() => put("/api/me/pane-focus", { body })).catch((err: unknown) => console.error("set pane focus", err));
|
|
|
|
|
};
|
|
|
|
|
const update = () => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (focused && inside && !inside.isConnected && document.activeElement === document.body) {
|
|
|
|
|
// A re-render removed the focused element (a tab button, a list row); that isn't the human leaving.
|
|
|
|
|
pane.focus({ preventScroll: true });
|
|
|
|
|
}
|
|
|
|
|
const active = document.activeElement;
|
|
|
|
|
const now = document.hasFocus() && pane.contains(active);
|
|
|
|
|
inside = now ? active : null;
|
|
|
|
|
if (now === focused) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
focused = now;
|
|
|
|
|
send();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
on("connection", () => {
|
|
|
|
|
if (state.connected && focused) {
|
|
|
|
|
send();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
document.addEventListener("focusin", update);
|
|
|
|
|
document.addEventListener("focusout", update);
|
|
|
|
|
addEventListener("focus", update);
|
|
|
|
|
addEventListener("blur", update);
|
|
|
|
|
addEventListener("pagehide", () => {
|
|
|
|
|
if (focused) {
|
|
|
|
|
focused = false;
|
|
|
|
|
void put("/api/me/pane-focus", { body: { focused: false }, keepalive: true });
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-10-14 09:40:12 -07:00
|
|
|
}
|