// @ts-check // The Review tab: the open review's guide, which the host draws as the TUI's guide pane, and a // tapped chapter open in the peek with its notes, diffs and comments. Reviewed marks the chapter // walked, as reading to its end does in the TUI, Next opens the one after, and Comment writes on // the picked lines or the chapter. import { useEffect, useState } from "preact/hooks"; import { chapterPiece, guidePiece, nextChapter, targetName } from "./review.js"; import { useRendered } from "./render.js"; import { html, landedIn } from "./html.js"; import { useEscape } from "./dock.js"; import { Icon } from "./icons.js"; import { PickablePiece } from "./lines-view.js"; import { CommentSheet, Unsent, composeAt, composedEdit, tapCard } from "./comments-view.js"; /** @import { PanelHooks } from "./panel.js" */ /** @import { ReviewShown } from "./review.js" */ /** @import { Composing } from "./comments-view.js" */ /** @param {{ hooks: PanelHooks }} props */ export function ReviewTab({ hooks }) { const { review, send } = hooks; useEffect(() => void review.ask(send), []); const shown = review.shown.value; if (!shown.review) return html`<${Empty} shown=${shown} hooks=${hooks} />`; return html`
${targetName(shown.review.target)}
<${Unsent} shown=${shown} hooks=${hooks} /> <${Guide} shown=${shown} hooks=${hooks} />`; } /** @param {{ shown: ReviewShown, hooks: PanelHooks }} props */ function Guide({ shown, hooks }) { const rendered = useRendered(guidePiece(shown), false); return html`Connection lost. ${again("Try again", () => review.ask(send))}
`; case "failed": return html`${shown.error} ${again("Try again", () => review.load(send))}
`; case "loading": return html`Reading the changes…
`; case "shown": return html`No review is open. ${again("Review changes", () => review.load(send))}
`; default: return html`Loading…
`; } } /** A tap on a chapter opens it in the peek, in place of any other pane. @param {MouseEvent} event @param {PanelHooks} hooks */ export function tapChapter(event, { review, files, github }) { const chapter = /** @type {HTMLElement | null} */ (landedIn(event, "[data-chapter]")); if (!chapter?.dataset.chapter) return; files.close(); github.close(); review.pick(chapter.dataset.chapter); } /** * The open chapter, in the pane a file opens in. Escape closes it before the panel. * @param {{ hooks: PanelHooks, wide: boolean }} props */ export function ReviewPeek({ hooks, wide }) { const { review, send } = hooks; const id = review.open.value; const [composing, compose] = useState(/** @type {Composing | null} */ (null)); useEffect(() => compose(null), [id]); useEscape(composing ? () => compose(null) : id ? review.close : null); const shown = review.shown.value; if (!id || !shown.review) return null; const piece = chapterPiece(shown, id); const submit = (/** @type {string} */ body, /** @type {boolean} */ question, /** @type {boolean} */ now) => composing && (review.edit(send, composedEdit(composing, body, question, now)), compose(null)); return html`${shown.problem}
` : null}