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; }; 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 && ( <>
Edit title
)}
{patch.status} {canEdit && (
{user?.isAdmin && patch.status === "open" && applyResult?.status === "clean" && (
)} {user?.isAdmin && patch.status !== "merged" && (
)}
Delete
Permanently delete this patch?
)}
{/* Subview tabs */} {tab === "conversation" ? (
{/* Patch description */}
{displayName(patch.author_username)}
{canEdit && (
Edit Stop editing
)}
{canEdit && (
)}
{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.bodyHtml}
))} {user && (

Add a comment