// @ts-check // The project panel: the TUI's views of the project, gathered behind one header button. On a phone // it covers the page and holds the dock's plan and changes too, so one button reaches everything; // on a wide screen it's a rail in the dock's place, as the TUI keeps FILES in its dock, and a file, // a pull request or a review chapter opens in a pane beside it, leaving the conversation up where // there's room. One pane at a time: opening one closes the others. import { signal } from "@preact/signals"; import { DockTab, useEscape } from "./dock.js"; import { FilePeek, FilesTab } from "./files-view.js"; import { GithubPeek, GithubTab } from "./github-view.js"; import { html } from "./html.js"; import { Icon } from "./icons.js"; import { panelTabs, shownTab, useWide } from "./layout.js"; import { useRendered } from "./render.js"; import { ReviewPeek, ReviewTab } from "./review-view.js"; /** @import { Frame } from "./connection.js" */ /** @import { Listings } from "./picker.js" */ /** * @typedef {import("./layout.js").Tab} Tab * @typedef {ReturnType} Panel * @typedef {{ send: (frame: Frame) => boolean, listings: Listings, files: ReturnType, * github: ReturnType, review: ReturnType, * mention: (words: string) => void, changes: any, todos: any, openDiff: (path: string) => void, diffOpen: boolean, * project: Project }} PanelHooks * @typedef {{ name: string, branch: string | null, dirty: boolean }} Project */ /** @type {Record any>} */ const TAB_VIEWS = { dock: DockTab, files: FilesTab, github: GithubTab, review: ReviewTab }; /** Closed; `open` shows a tab, the screen's first unless told. */ export function createPanel() { const tab = signal(/** @type {Tab | null} */ (null)); return { tab, open: (/** @type {Tab | null} */ id = null) => (tab.value = id ?? "dock"), close: () => (tab.value = null) }; } /** The header's button that opens the panel. @param {{ open: () => void }} props */ export function PanelButton({ open }) { const label = useWide() ? "Project" : "Dock and project"; return html``; } /** @param {{ panel: Panel, hooks: PanelHooks }} props */ export function ProjectPanel({ panel, hooks }) { const wide = useWide(); // an open file, item or diff takes Escape first useEscape(panel.tab.value && !paneOpen(hooks) ? panel.close : null); if (!panel.tab.value) return null; const tab = shownTab(panel.tab.value, wide); /** @param {Tab} next */ const pick = (next) => switchTab(panel, hooks, next); return html` <${FilePeek} hooks=${hooks} wide=${wide} /> <${GithubPeek} hooks=${hooks} wide=${wide} /> <${ReviewPeek} hooks=${hooks} wide=${wide} />`; } /** Whether a file, an item, a chapter or a diff is open over the panel. @param {PanelHooks} hooks */ const paneOpen = ({ files, github, review, diffOpen }) => Boolean(files.open.value || github.open.value || review.open.value || diffOpen); /** * The folder the session works in and its branch, as the TUI's project section has them, in the * session's header and the panel's. The host draws it so the glyphs are the TUI's, at the tree's * tier; the bare name stands in until it does. * @param {{ project: Project }} props */ export function ProjectName({ project }) { const rendered = useRendered({ kind: "project_name", ...project }, true); if (!project.name) return null; if (!rendered) return html`${project.name}`; return html``; } /** Shows `next`, closing the pane the last tab opened. @param {Panel} panel @param {PanelHooks} hooks @param {Tab} next */ function switchTab(panel, hooks, next) { hooks.files.close(); hooks.github.close(); hooks.review.close(); panel.open(next); } /** @param {{ tab: Tab, pick: (tab: Tab) => void, wide: boolean }} props */ function Tabs({ tab, pick, wide }) { return html``; }