// @ts-check // The GitHub tab: `/github`'s sections as badges, the shown one's rows as the TUI draws them, and // a tapped row open in the peek, its header over an Overview and a Conversation. The host draws // every row, check and card; the app only says which, and owns the taps. import { useEffect } from "preact/hooks"; import { githubMention, rowSubject, shownSection } from "./github.js"; import { useRendered } from "./render.js"; import { html, landedIn } from "./html.js"; import { useEscape } from "./dock.js"; import { Icon } from "./icons.js"; /** @import { PanelHooks } from "./panel.js" */ /** @import { OpenItem, Reading, Subject } from "./github.js" */ /** @param {{ hooks: PanelHooks }} props */ export function GithubTab({ hooks }) { const { github, send } = hooks; useEffect(() => void github.list(send), []); const listing = github.listing.value; if (listing.state === "lost" && !listing.sections.length) return html`<${Lost} retry=${() => github.list(send)} />`; if (!listing.sections.length) return html`
${listing.state === "listed" ? "No sections" : "Loading…"}
`; const shown = shownSection(listing.sections, github.section.value); return html`<${Sections} sections=${listing.sections} shown=${shown.name} pick=${github.pick} /> <${List} hooks=${hooks} section=${shown} />`; } /** @param {{ retry: () => void }} props */ function Lost({ retry }) { return html`Connection lost.
`; } /** * The section tabs on one line, as `/github` draws them: the open one a slab, the rest quiet * words, each with how many it holds, scrolling sideways when they don't fit. * @param {{ sections: any[], shown: string, pick: (name: string) => void }} props */ function Sections({ sections, shown, pick }) { return html``; } /** @param {{ hooks: PanelHooks, section: any }} props */ function List({ hooks, section }) { const { repository, at } = hooks.github.listing.value; const rendered = useRendered({ kind: "github_list", repository, section, now: at }, false); return html`${reading.error}
`; return html`Reading the ${what}…
`; } /** * The detail's tabs, on the TUI's tab line, Conversation counting what's been said. * @param {{ tab: import("./github.js").DetailTab, show: (tab: import("./github.js").DetailTab) => void, said: number }} props */ function DetailTabs({ tab, show, said }) { /** @type {[import("./github.js").DetailTab, string][]} */ const tabs = [["overview", "Overview"], ["conversation", said ? `Conversation ${said}` : "Conversation"]]; return html``; } /** @param {{ piece: import("./render.js").Piece }} props */ function Piece({ piece }) { const rendered = useRendered(piece, false); return html``; } /** * Taps inside the detail: "open #N" opens that pull request, "more lines in Conversation" shows * it, and "Show all" unfolds a long comment. @param {MouseEvent} event @param {PanelHooks} hooks */ export function tapDetail(event, { github, send }) { const item = github.open.value; const open = landedIn(event, "button.gh-open"); if (item && open) return github.read(linkedSubject(item.subject, Number(open.dataset.number), github.listing.value.repository), send); if (landedIn(event, "button.gh-more")) return github.show("conversation"); landedIn(event, "button.gh-unfold")?.closest(".gh-card")?.classList.remove("folded"); } /** * The pull request `number` in the same repository as `subject`. * @param {Subject} subject @param {number} number @param {string | null} here @returns {Subject} */ export function linkedSubject(subject, number, here) { const repository = subject.repository ?? here; return { number, pull_request: true, repository: subject.repository, url: `https://github.com/${repository}/pull/${number}` }; }