115 lines
4.8 KiB
JavaScript
115 lines
4.8 KiB
JavaScript
import { put } from "./api.js";
|
|
import { mountChanges } from "./changes.js";
|
|
import { h, replace } from "./dom.js";
|
|
import { mountFiles } from "./files.js";
|
|
import { mountInbox } from "./inbox.js";
|
|
import { mountLead } from "./lead.js";
|
|
import { openSwitcher } from "./navbar.js";
|
|
import { findTask, focusedProject, focusTab, on, onEach, state, tabs } from "./state.js";
|
|
import { mountPreview } from "./preview.js";
|
|
import { mountProject } from "./project.js";
|
|
import { mountReviews } from "./reviews.js";
|
|
import { mountTranscript } from "./task.js";
|
|
import { mountTerminal } from "./terminal.js";
|
|
const views = {
|
|
transcript: { label: "Transcript", mount: mountTranscript },
|
|
changes: { label: "Changes", mount: (root) => mountChanges(root) },
|
|
files: { label: "Files", mount: mountFiles },
|
|
terminal: { label: "Terminal", mount: mountTerminal },
|
|
preview: { label: "Preview", mount: mountPreview },
|
|
inbox: { label: "Inbox", mount: mountInbox },
|
|
reviews: { label: "Reviews", mount: mountReviews },
|
|
project: { label: "Project", mount: mountProject },
|
|
};
|
|
export function leadPane() {
|
|
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));
|
|
}
|
|
export function taskPane() {
|
|
const strip = h("nav", { class: "pane-tabs" });
|
|
const body = h("div", { class: "pane-body" });
|
|
const picker = h("button", { class: "task-picker", title: "Switch task (⌘K)" });
|
|
picker.onclick = openSwitcher;
|
|
const pane = h("section", { class: "pane task-pane", tabIndex: -1 }, strip, body);
|
|
let shown;
|
|
let dispose = () => { };
|
|
const renderPicker = () => {
|
|
const task = state.selectedTaskId ? findTask(state.selectedTaskId) : undefined;
|
|
const project = focusedProject();
|
|
if (task) {
|
|
pane.style.setProperty("--task", `var(--task-${task.color})`);
|
|
}
|
|
else {
|
|
pane.style.removeProperty("--task");
|
|
}
|
|
replace(picker, task ? `${project?.name ?? ""} ▸ ${task.title}` : (project?.name ?? "No task"), " ▾");
|
|
};
|
|
const render = () => {
|
|
const first = state.focus.tabs.filter((t, i, all) => tabs.includes(t) && all.indexOf(t) === i);
|
|
const order = [...first, ...tabs.filter((t) => !first.includes(t))];
|
|
const tab = state.focus.tab;
|
|
const waiting = state.inbox.filter((item) => item.task_id === state.selectedTaskId).length;
|
|
replace(strip, ...order.map((t) => {
|
|
const attention = t === "inbox" && waiting > 0;
|
|
const b = h("button", { class: [t === tab ? "active" : "", attention ? "attention" : ""].join(" ").trim() }, views[t].label, attention && h("span", { class: "badge", title: "inbox items" }, waiting));
|
|
b.onclick = () => focusTab(t);
|
|
return b;
|
|
}), h("span", { class: "spacer" }), picker);
|
|
if (tab === shown) {
|
|
return;
|
|
}
|
|
dispose();
|
|
shown = tab;
|
|
const root = h("div", { class: `view view-${tab}` });
|
|
replace(body, root);
|
|
dispose = views[tab].mount(root);
|
|
};
|
|
onEach(["focus", "inbox", "selection"], render);
|
|
onEach(["projects", "tasks", "selection", "focus"], renderPicker);
|
|
render();
|
|
renderPicker();
|
|
trackPaneFocus(pane);
|
|
return pane;
|
|
}
|
|
function trackPaneFocus(pane) {
|
|
let focused = false;
|
|
let inside = null;
|
|
let sending = Promise.resolve();
|
|
const send = () => {
|
|
const body = { focused };
|
|
sending = sending.then(() => put("/api/me/pane-focus", { body })).catch((err) => 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 });
|
|
}
|
|
});
|
|
}
|
|
//# sourceMappingURL=panes.js.map
|