import { escapeHtml } from "@kitajs/html"; import type { PatchCommentRow, PatchRow, RepositoryRow, } from "../../db/index.ts"; import { displayName } from "../../lib/users.ts"; import type { SessionUser } from "../../middleware/session.ts"; import type { RenderedDiffFile } from "../../services/diffHighlight.ts"; import type { ApplyResult } from "../../services/patchCache.ts"; import { Avatar } from "../Avatar.tsx"; import { DateWithEdited } from "../DateWithEdited.tsx"; import { DiffView } from "../DiffView.tsx"; import { Layout } from "../layout.tsx"; import { ReactionBar, type ReactionCount } from "../ReactionBar.tsx"; import { RepoHeader } from "../repos/RepoHeader.tsx"; import { RepoNav } from "../repos/RepoNav.tsx"; interface PatchDetailProps { user: SessionUser | null; repo: RepositoryRow; patch: PatchRow & { author_username: string; author_avatar_version: number | null; author_name: string; author_email: string; }; descriptionHtml: string; applyResult: ApplyResult | null; files: RenderedDiffFile[]; tab: "conversation" | "changes"; comments: (PatchCommentRow & { author_username: string; author_avatar_version: number | null; bodyHtml: string; })[]; reactions: ReactionCount[]; commentReactions: Map; } export function PatchDetail({ user, repo, patch, descriptionHtml, applyResult, files, tab, comments, reactions, commentReactions, }: PatchDetailProps) { const canEdit = user != null && (user.isAdmin || (user.id === patch.author_id && patch.status === "open")); const canEditComment = (c: PatchCommentRow) => user != null && (user.isAdmin || (user.id === c.author_id && patch.status === "open")); const baseUrl = `/${repo.name}/patches/${patch.number}`; const reactUrl = `${baseUrl}/react`; return ( #{patch.number} {patch.title} {canEdit && ( <> Save Cancel Edit title > )} {patch.status} {canEdit && ( {user?.isAdmin && patch.status === "open" && applyResult?.status === "clean" && ( Merge patch )} {user?.isAdmin && patch.status !== "merged" && ( {patch.status === "open" ? "Close patch" : "Reopen patch"} )} Delete Permanently delete this patch? Yes, delete )} git author: {escapeHtml(`${patch.author_name} <${patch.author_email}>`)} {/* Subview tabs */} Conversation{" "} {comments.length > 0 && ( {comments.length} )} Changes{" "} {files.length > 0 && ( {files.length} )} {tab === "conversation" ? ( {/* Patch description */} {displayName(patch.author_username)} {canEdit && ( Edit Stop editing )} {canEdit && ( {patch.description} Save )} {descriptionHtml || ( No description provided. )} {/* Apply status */} {applyResult && ( {applyResult.status === "clean" ? "✓" : "✗"} {applyResult.status === "clean" ? "Applies cleanly" : "Has conflicts"} {applyResult.output && ( {applyResult.output} )} )} {/* Comments */} {comments.map((comment) => ( {displayName(comment.author_username)} {canEditComment(comment) && ( Edit Stop editing )} {canEditComment(comment) && ( {comment.body} Save )} {comment.bodyHtml} ))} {user && ( Add a comment Comment )} {!user && ( Sign in to leave a comment. )} ) : ( )} ); }
{applyResult.output}
Sign in to leave a comment.