| 12ffdd4 | | | 1 | "use client"; |
| 12ffdd4 | | | 2 | |
| 12ffdd4 | | | 3 | import { useState, useEffect } from "react"; |
| 3e3af55 | | | 4 | import Link from "next/link"; |
| 12ffdd4 | | | 5 | import { useAuth } from "@/lib/auth"; |
| 12ffdd4 | | | 6 | import { |
| d12933e | | | 7 | diffs, |
| 12ffdd4 | | | 8 | repos, |
| d12933e | | | 9 | type Diff, |
| 12ffdd4 | | | 10 | type Comment, |
| 12ffdd4 | | | 11 | type Review, |
| 12ffdd4 | | | 12 | } from "@/lib/api"; |
| bf5fc33 | | | 13 | import { Skeleton } from "@/app/components/skeleton"; |
| 3e3af55 | | | 14 | |
| 3e3af55 | | | 15 | interface Props { |
| 3e3af55 | | | 16 | params: Promise<{ owner: string; repo: string; number: string }>; |
| 3e3af55 | | | 17 | } |
| 3e3af55 | | | 18 | |
| 3e3af55 | | | 19 | function timeAgo(dateStr: string): string { |
| 3e3af55 | | | 20 | const seconds = Math.floor( |
| 3e3af55 | | | 21 | (Date.now() - new Date(dateStr).getTime()) / 1000 |
| 3e3af55 | | | 22 | ); |
| 3e3af55 | | | 23 | if (seconds < 60) return "just now"; |
| 3e3af55 | | | 24 | if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`; |
| 3e3af55 | | | 25 | if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`; |
| 3e3af55 | | | 26 | if (seconds < 2592000) return `${Math.floor(seconds / 86400)}d ago`; |
| 3e3af55 | | | 27 | return new Date(dateStr).toLocaleDateString(); |
| 3e3af55 | | | 28 | } |
| 3e3af55 | | | 29 | |
| 12ffdd4 | | | 30 | interface DiffFile { |
| 12ffdd4 | | | 31 | path: string; |
| 12ffdd4 | | | 32 | hunks: DiffHunk[]; |
| 12ffdd4 | | | 33 | } |
| 12ffdd4 | | | 34 | |
| 12ffdd4 | | | 35 | interface DiffHunk { |
| 12ffdd4 | | | 36 | header: string; |
| 12ffdd4 | | | 37 | lines: DiffLine[]; |
| 12ffdd4 | | | 38 | } |
| 12ffdd4 | | | 39 | |
| 12ffdd4 | | | 40 | interface DiffLine { |
| 12ffdd4 | | | 41 | type: "add" | "del" | "context"; |
| 12ffdd4 | | | 42 | content: string; |
| 12ffdd4 | | | 43 | oldNum: number | null; |
| 12ffdd4 | | | 44 | newNum: number | null; |
| 12ffdd4 | | | 45 | } |
| 12ffdd4 | | | 46 | |
| 12ffdd4 | | | 47 | /** Parse unified diff hunks from a diff string (single file or full) */ |
| 12ffdd4 | | | 48 | function parseUnifiedDiff(raw: string): DiffHunk[] { |
| 12ffdd4 | | | 49 | const hunks: DiffHunk[] = []; |
| 12ffdd4 | | | 50 | let currentHunk: DiffHunk | null = null; |
| 12ffdd4 | | | 51 | let oldLine = 0; |
| 12ffdd4 | | | 52 | let newLine = 0; |
| 12ffdd4 | | | 53 | |
| 12ffdd4 | | | 54 | for (const line of raw.split("\n")) { |
| 12ffdd4 | | | 55 | const hunkMatch = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)/); |
| 12ffdd4 | | | 56 | if (hunkMatch) { |
| 12ffdd4 | | | 57 | currentHunk = { header: line, lines: [] }; |
| 12ffdd4 | | | 58 | hunks.push(currentHunk); |
| 12ffdd4 | | | 59 | oldLine = parseInt(hunkMatch[1]); |
| 12ffdd4 | | | 60 | newLine = parseInt(hunkMatch[2]); |
| 12ffdd4 | | | 61 | continue; |
| 12ffdd4 | | | 62 | } |
| 12ffdd4 | | | 63 | if (!currentHunk) continue; |
| 12ffdd4 | | | 64 | if (line.startsWith("+")) { |
| 12ffdd4 | | | 65 | currentHunk.lines.push({ type: "add", content: line.slice(1), oldNum: null, newNum: newLine++ }); |
| 12ffdd4 | | | 66 | } else if (line.startsWith("-")) { |
| 12ffdd4 | | | 67 | currentHunk.lines.push({ type: "del", content: line.slice(1), oldNum: oldLine++, newNum: null }); |
| 12ffdd4 | | | 68 | } else if (line.startsWith(" ") || line === "") { |
| 12ffdd4 | | | 69 | currentHunk.lines.push({ type: "context", content: line.slice(1), oldNum: oldLine++, newNum: newLine++ }); |
| 12ffdd4 | | | 70 | } |
| 12ffdd4 | | | 71 | } |
| 12ffdd4 | | | 72 | return hunks; |
| 12ffdd4 | | | 73 | } |
| 12ffdd4 | | | 74 | |
| 12ffdd4 | | | 75 | /** Parse a full multi-file git diff string */ |
| 12ffdd4 | | | 76 | function parseDiff(raw: string): DiffFile[] { |
| 12ffdd4 | | | 77 | const files: DiffFile[] = []; |
| 12ffdd4 | | | 78 | const fileChunks = raw.split(/^diff --git /m).filter(Boolean); |
| 12ffdd4 | | | 79 | |
| 12ffdd4 | | | 80 | for (const chunk of fileChunks) { |
| 12ffdd4 | | | 81 | const lines = chunk.split("\n"); |
| 12ffdd4 | | | 82 | const headerMatch = lines[0]?.match(/a\/(.+?) b\/(.+)/); |
| 12ffdd4 | | | 83 | const path = headerMatch ? headerMatch[2] : "unknown"; |
| 12ffdd4 | | | 84 | const hunks = parseUnifiedDiff(chunk); |
| 12ffdd4 | | | 85 | if (hunks.length > 0) { |
| 12ffdd4 | | | 86 | files.push({ path, hunks }); |
| 12ffdd4 | | | 87 | } |
| 12ffdd4 | | | 88 | } |
| 12ffdd4 | | | 89 | return files; |
| 12ffdd4 | | | 90 | } |
| 12ffdd4 | | | 91 | |
| d12933e | | | 92 | export default function DiffDetailPage({ params }: Props) { |
| 12ffdd4 | | | 93 | const { user } = useAuth(); |
| 12ffdd4 | | | 94 | const [owner, setOwner] = useState(""); |
| 12ffdd4 | | | 95 | const [repo, setRepo] = useState(""); |
| d12933e | | | 96 | const [diffNumber, setDiffNumber] = useState(0); |
| d12933e | | | 97 | const [diff, setDiff] = useState<Diff | null>(null); |
| 12ffdd4 | | | 98 | const [comments, setComments] = useState<Comment[]>([]); |
| 12ffdd4 | | | 99 | const [reviews, setReviews] = useState<Review[]>([]); |
| 12ffdd4 | | | 100 | const [diffFiles, setDiffFiles] = useState<DiffFile[]>([]); |
| 12ffdd4 | | | 101 | const [loading, setLoading] = useState(true); |
| 12ffdd4 | | | 102 | const [activeTab, setActiveTab] = useState<"conversation" | "changes">("conversation"); |
| 3e3af55 | | | 103 | |
| 12ffdd4 | | | 104 | // Comment form |
| 12ffdd4 | | | 105 | const [commentBody, setCommentBody] = useState(""); |
| 12ffdd4 | | | 106 | const [commenting, setCommenting] = useState(false); |
| 12ffdd4 | | | 107 | |
| 12ffdd4 | | | 108 | // Action states |
| 2ec6868 | | | 109 | const [landing, setLanding] = useState(false); |
| 12ffdd4 | | | 110 | const [closing, setClosing] = useState(false); |
| 12ffdd4 | | | 111 | const [actionError, setActionError] = useState(""); |
| 12ffdd4 | | | 112 | |
| 12ffdd4 | | | 113 | useEffect(() => { |
| 12ffdd4 | | | 114 | params.then(({ owner, repo, number }) => { |
| 12ffdd4 | | | 115 | setOwner(owner); |
| 12ffdd4 | | | 116 | setRepo(repo); |
| d12933e | | | 117 | setDiffNumber(parseInt(number)); |
| d12933e | | | 118 | document.title = `D${number} · ${repo}`; |
| 12ffdd4 | | | 119 | }); |
| 12ffdd4 | | | 120 | }, [params]); |
| 12ffdd4 | | | 121 | |
| 1da9874 | | | 122 | useEffect(() => { |
| d12933e | | | 123 | if (diff) { |
| d12933e | | | 124 | document.title = `${diff.title} D${diff.number} · ${repo}`; |
| 1da9874 | | | 125 | } |
| d12933e | | | 126 | }, [diff, owner, repo]); |
| 1da9874 | | | 127 | |
| 12ffdd4 | | | 128 | useEffect(() => { |
| d12933e | | | 129 | if (!owner || !diffNumber) return; |
| 12ffdd4 | | | 130 | loadData(); |
| d12933e | | | 131 | }, [owner, repo, diffNumber]); |
| 12ffdd4 | | | 132 | |
| 12ffdd4 | | | 133 | async function loadData() { |
| 12ffdd4 | | | 134 | setLoading(true); |
| 12ffdd4 | | | 135 | try { |
| d12933e | | | 136 | const data = await diffs.get(owner, repo, diffNumber); |
| d12933e | | | 137 | setDiff(data.diff); |
| 12ffdd4 | | | 138 | setComments(data.comments); |
| 12ffdd4 | | | 139 | setReviews(data.reviews); |
| 12ffdd4 | | | 140 | |
| 12ffdd4 | | | 141 | // Fetch diff |
| d12933e | | | 142 | if (data.diff.status === "open") { |
| 12ffdd4 | | | 143 | try { |
| 2ec6868 | | | 144 | const base = data.diff.base_commit ?? data.diff.head_commit + '^'; |
| 12ffdd4 | | | 145 | const diffData = await repos.diff( |
| 12ffdd4 | | | 146 | owner, |
| 12ffdd4 | | | 147 | repo, |
| 2ec6868 | | | 148 | base, |
| 2ec6868 | | | 149 | data.diff.head_commit |
| 12ffdd4 | | | 150 | ); |
| 12ffdd4 | | | 151 | if (diffData.diffs) { |
| 12ffdd4 | | | 152 | const parsed: DiffFile[] = []; |
| 12ffdd4 | | | 153 | for (const d of diffData.diffs) { |
| 12ffdd4 | | | 154 | if (d.is_binary) continue; |
| 12ffdd4 | | | 155 | const hunks = parseUnifiedDiff(d.diff); |
| 12ffdd4 | | | 156 | if (hunks.length > 0) { |
| 12ffdd4 | | | 157 | parsed.push({ path: d.path, hunks }); |
| 12ffdd4 | | | 158 | } |
| 12ffdd4 | | | 159 | } |
| 12ffdd4 | | | 160 | setDiffFiles(parsed); |
| 12ffdd4 | | | 161 | } |
| 12ffdd4 | | | 162 | } catch { |
| 12ffdd4 | | | 163 | // Diff may not be available |
| 12ffdd4 | | | 164 | } |
| 12ffdd4 | | | 165 | } |
| 12ffdd4 | | | 166 | } catch { |
| d12933e | | | 167 | // Diff not found |
| 12ffdd4 | | | 168 | } finally { |
| 12ffdd4 | | | 169 | setLoading(false); |
| 12ffdd4 | | | 170 | } |
| 12ffdd4 | | | 171 | } |
| 12ffdd4 | | | 172 | |
| 2ec6868 | | | 173 | async function handleLand() { |
| 12ffdd4 | | | 174 | setActionError(""); |
| 2ec6868 | | | 175 | setLanding(true); |
| 12ffdd4 | | | 176 | try { |
| 2ec6868 | | | 177 | const { diff: updated } = await diffs.land(owner, repo, diffNumber); |
| d12933e | | | 178 | setDiff(updated); |
| 12ffdd4 | | | 179 | } catch (err: unknown) { |
| 2ec6868 | | | 180 | setActionError(err instanceof Error ? err.message : "Land failed"); |
| 12ffdd4 | | | 181 | } finally { |
| 2ec6868 | | | 182 | setLanding(false); |
| 12ffdd4 | | | 183 | } |
| 12ffdd4 | | | 184 | } |
| 12ffdd4 | | | 185 | |
| 12ffdd4 | | | 186 | async function handleClose() { |
| 12ffdd4 | | | 187 | setActionError(""); |
| 12ffdd4 | | | 188 | setClosing(true); |
| 12ffdd4 | | | 189 | try { |
| d12933e | | | 190 | const { diff: updated } = await diffs.update(owner, repo, diffNumber, { status: "closed" }); |
| d12933e | | | 191 | setDiff(updated); |
| 12ffdd4 | | | 192 | } catch (err: unknown) { |
| 12ffdd4 | | | 193 | setActionError(err instanceof Error ? err.message : "Failed to close"); |
| 12ffdd4 | | | 194 | } finally { |
| 12ffdd4 | | | 195 | setClosing(false); |
| 12ffdd4 | | | 196 | } |
| 12ffdd4 | | | 197 | } |
| 12ffdd4 | | | 198 | |
| 12ffdd4 | | | 199 | async function handleReopen() { |
| 12ffdd4 | | | 200 | setActionError(""); |
| 12ffdd4 | | | 201 | try { |
| d12933e | | | 202 | const { diff: updated } = await diffs.update(owner, repo, diffNumber, { status: "open" }); |
| d12933e | | | 203 | setDiff(updated); |
| 12ffdd4 | | | 204 | } catch (err: unknown) { |
| 12ffdd4 | | | 205 | setActionError(err instanceof Error ? err.message : "Failed to reopen"); |
| 12ffdd4 | | | 206 | } |
| 12ffdd4 | | | 207 | } |
| 12ffdd4 | | | 208 | |
| 12ffdd4 | | | 209 | async function handleComment(e: React.FormEvent) { |
| 12ffdd4 | | | 210 | e.preventDefault(); |
| 12ffdd4 | | | 211 | if (!commentBody.trim()) return; |
| 12ffdd4 | | | 212 | setCommenting(true); |
| 12ffdd4 | | | 213 | try { |
| d12933e | | | 214 | const { comment } = await diffs.comment(owner, repo, diffNumber, { |
| 12ffdd4 | | | 215 | body: commentBody, |
| 12ffdd4 | | | 216 | }); |
| 12ffdd4 | | | 217 | setComments((prev) => [...prev, comment]); |
| 12ffdd4 | | | 218 | setCommentBody(""); |
| 12ffdd4 | | | 219 | } catch { |
| 12ffdd4 | | | 220 | // silently fail |
| 12ffdd4 | | | 221 | } finally { |
| 12ffdd4 | | | 222 | setCommenting(false); |
| 12ffdd4 | | | 223 | } |
| 12ffdd4 | | | 224 | } |
| 12ffdd4 | | | 225 | |
| d12933e | | | 226 | if (loading || !diff) { |
| 3e3af55 | | | 227 | return ( |
| bf5fc33 | | | 228 | <div className="max-w-3xl mx-auto px-4 py-6"> |
| bf5fc33 | | | 229 | {loading ? ( |
| bf5fc33 | | | 230 | <div className="space-y-4"> |
| bf5fc33 | | | 231 | <Skeleton width="200px" height="1.25rem" /> |
| bf5fc33 | | | 232 | <Skeleton width="100%" height="4rem" /> |
| bf5fc33 | | | 233 | <div className="flex gap-3"> |
| bf5fc33 | | | 234 | <Skeleton width="80px" height="2rem" /> |
| bf5fc33 | | | 235 | <Skeleton width="80px" height="2rem" /> |
| bf5fc33 | | | 236 | </div> |
| bf5fc33 | | | 237 | <Skeleton width="100%" height="6rem" /> |
| bf5fc33 | | | 238 | </div> |
| bf5fc33 | | | 239 | ) : ( |
| bf5fc33 | | | 240 | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| d12933e | | | 241 | Diff not found |
| bf5fc33 | | | 242 | </p> |
| bf5fc33 | | | 243 | )} |
| 3e3af55 | | | 244 | </div> |
| 3e3af55 | | | 245 | ); |
| 3e3af55 | | | 246 | } |
| 3e3af55 | | | 247 | |
| 12ffdd4 | | | 248 | // Merge activity into a single timeline sorted by date |
| 12ffdd4 | | | 249 | const activity = [ |
| 12ffdd4 | | | 250 | ...comments.map((c) => ({ ...c, kind: "comment" as const })), |
| 12ffdd4 | | | 251 | ...reviews.map((r) => ({ ...r, kind: "review" as const })), |
| 12ffdd4 | | | 252 | ].sort( |
| 12ffdd4 | | | 253 | (a, b) => |
| 12ffdd4 | | | 254 | new Date(a.created_at).getTime() - new Date(b.created_at).getTime() |
| 12ffdd4 | | | 255 | ); |
| 3e3af55 | | | 256 | |
| 3e3af55 | | | 257 | return ( |
| 135dfe5 | | | 258 | <div className="max-w-3xl mx-auto px-4 py-6"> |
| 135dfe5 | | | 259 | <div className="text-sm mb-1"> |
| 3e3af55 | | | 260 | <Link |
| d12933e | | | 261 | href={`/${owner}/${repo}/diffs`} |
| 135dfe5 | | | 262 | style={{ color: "var(--text-muted)" }} |
| 135dfe5 | | | 263 | className="hover:underline" |
| 3e3af55 | | | 264 | > |
| d12933e | | | 265 | Diffs |
| 3e3af55 | | | 266 | </Link> |
| 135dfe5 | | | 267 | </div> |
| cf89d3c | | | 268 | <h1 className="text-lg mb-1"> |
| d12933e | | | 269 | {diff.title} |
| 135dfe5 | | | 270 | <span className="font-normal" style={{ color: "var(--text-muted)" }}> |
| d12933e | | | 271 | {" "}D{diff.number} |
| 135dfe5 | | | 272 | </span> |
| 135dfe5 | | | 273 | </h1> |
| 135dfe5 | | | 274 | <div className="text-sm mb-6" style={{ color: "var(--text-muted)" }}> |
| 135dfe5 | | | 275 | <span |
| 135dfe5 | | | 276 | className="capitalize" |
| 135dfe5 | | | 277 | style={{ |
| 135dfe5 | | | 278 | color: |
| d12933e | | | 279 | diff.status === "open" |
| 135dfe5 | | | 280 | ? "var(--status-open-text)" |
| 2ec6868 | | | 281 | : diff.status === "landed" |
| 135dfe5 | | | 282 | ? "var(--status-merged-text)" |
| 135dfe5 | | | 283 | : "var(--status-closed-text)", |
| 135dfe5 | | | 284 | }} |
| 135dfe5 | | | 285 | > |
| d12933e | | | 286 | {diff.status} |
| 135dfe5 | | | 287 | </span> |
| 135dfe5 | | | 288 | {" \u2014 "} |
| 2ec6868 | | | 289 | {diff.author_name} submitted{" "} |
| 2ec6868 | | | 290 | <code className="text-xs font-mono">{diff.head_commit?.slice(0, 12)}</code> |
| 3e3af55 | | | 291 | </div> |
| 3e3af55 | | | 292 | |
| d12933e | | | 293 | {diff.description && ( |
| 135dfe5 | | | 294 | <div |
| 135dfe5 | | | 295 | className="text-sm mb-6 pb-6" |
| 135dfe5 | | | 296 | style={{ |
| 135dfe5 | | | 297 | color: "var(--text-secondary)", |
| 135dfe5 | | | 298 | borderBottom: "1px solid var(--border)", |
| 135dfe5 | | | 299 | }} |
| 135dfe5 | | | 300 | > |
| d12933e | | | 301 | <p className="whitespace-pre-wrap">{diff.description}</p> |
| 135dfe5 | | | 302 | </div> |
| 135dfe5 | | | 303 | )} |
| 3e3af55 | | | 304 | |
| 2ec6868 | | | 305 | {/* Land / Close actions */} |
| d12933e | | | 306 | {user && diff.status === "open" && ( |
| 135dfe5 | | | 307 | <div |
| 12ffdd4 | | | 308 | className="flex items-center gap-3 mb-6 pb-6" |
| 12ffdd4 | | | 309 | style={{ borderBottom: "1px solid var(--border)" }} |
| 135dfe5 | | | 310 | > |
| 12ffdd4 | | | 311 | <button |
| 2ec6868 | | | 312 | onClick={handleLand} |
| 2ec6868 | | | 313 | disabled={landing} |
| 12ffdd4 | | | 314 | className="text-sm px-3 py-1" |
| 12ffdd4 | | | 315 | style={{ |
| 12ffdd4 | | | 316 | backgroundColor: "var(--status-merged-bg)", |
| 12ffdd4 | | | 317 | color: "var(--status-merged-text)", |
| 12ffdd4 | | | 318 | border: "none", |
| 2ec6868 | | | 319 | cursor: landing ? "default" : "pointer", |
| 2ec6868 | | | 320 | opacity: landing ? 0.5 : 1, |
| 12ffdd4 | | | 321 | font: "inherit", |
| 12ffdd4 | | | 322 | fontSize: "inherit", |
| 12ffdd4 | | | 323 | }} |
| 12ffdd4 | | | 324 | > |
| 2ec6868 | | | 325 | {landing ? "Landing..." : "Land"} |
| 12ffdd4 | | | 326 | </button> |
| 12ffdd4 | | | 327 | <button |
| 12ffdd4 | | | 328 | onClick={handleClose} |
| 12ffdd4 | | | 329 | disabled={closing} |
| 12ffdd4 | | | 330 | className="text-sm px-3 py-1" |
| 12ffdd4 | | | 331 | style={{ |
| 12ffdd4 | | | 332 | backgroundColor: "var(--bg-inset)", |
| 12ffdd4 | | | 333 | border: "1px solid var(--border)", |
| 12ffdd4 | | | 334 | color: "var(--text-muted)", |
| 12ffdd4 | | | 335 | cursor: closing ? "default" : "pointer", |
| 12ffdd4 | | | 336 | font: "inherit", |
| 12ffdd4 | | | 337 | fontSize: "inherit", |
| 12ffdd4 | | | 338 | }} |
| 12ffdd4 | | | 339 | > |
| 12ffdd4 | | | 340 | {closing ? "Closing..." : "Close"} |
| 12ffdd4 | | | 341 | </button> |
| 12ffdd4 | | | 342 | {actionError && ( |
| 12ffdd4 | | | 343 | <span className="text-xs" style={{ color: "var(--error-text)" }}> |
| 12ffdd4 | | | 344 | {actionError} |
| 135dfe5 | | | 345 | </span> |
| 135dfe5 | | | 346 | )} |
| 3e3af55 | | | 347 | </div> |
| 12ffdd4 | | | 348 | )} |
| 3e3af55 | | | 349 | |
| d12933e | | | 350 | {user && diff.status === "closed" && ( |
| 135dfe5 | | | 351 | <div |
| 12ffdd4 | | | 352 | className="mb-6 pb-6" |
| 12ffdd4 | | | 353 | style={{ borderBottom: "1px solid var(--border)" }} |
| 135dfe5 | | | 354 | > |
| 12ffdd4 | | | 355 | <button |
| 12ffdd4 | | | 356 | onClick={handleReopen} |
| 12ffdd4 | | | 357 | className="text-sm px-3 py-1" |
| 135dfe5 | | | 358 | style={{ |
| 12ffdd4 | | | 359 | backgroundColor: "var(--bg-inset)", |
| 12ffdd4 | | | 360 | border: "1px solid var(--border)", |
| 12ffdd4 | | | 361 | color: "var(--text-muted)", |
| 12ffdd4 | | | 362 | cursor: "pointer", |
| 12ffdd4 | | | 363 | font: "inherit", |
| 12ffdd4 | | | 364 | fontSize: "inherit", |
| 135dfe5 | | | 365 | }} |
| 135dfe5 | | | 366 | > |
| 12ffdd4 | | | 367 | Reopen |
| 12ffdd4 | | | 368 | </button> |
| 12ffdd4 | | | 369 | </div> |
| 12ffdd4 | | | 370 | )} |
| 12ffdd4 | | | 371 | |
| 12ffdd4 | | | 372 | {/* Tabs */} |
| 12ffdd4 | | | 373 | <div className="flex gap-4 text-sm mb-6"> |
| 12ffdd4 | | | 374 | <button |
| 12ffdd4 | | | 375 | onClick={() => setActiveTab("conversation")} |
| 12ffdd4 | | | 376 | className="hover:underline" |
| 12ffdd4 | | | 377 | style={{ |
| 12ffdd4 | | | 378 | color: activeTab === "conversation" ? "var(--text-primary)" : "var(--text-muted)", |
| 12ffdd4 | | | 379 | fontWeight: activeTab === "conversation" ? 600 : 400, |
| 12ffdd4 | | | 380 | background: "none", |
| 12ffdd4 | | | 381 | border: "none", |
| 12ffdd4 | | | 382 | cursor: "pointer", |
| 12ffdd4 | | | 383 | font: "inherit", |
| 12ffdd4 | | | 384 | fontSize: "inherit", |
| 12ffdd4 | | | 385 | }} |
| 12ffdd4 | | | 386 | > |
| 12ffdd4 | | | 387 | Conversation |
| 12ffdd4 | | | 388 | </button> |
| 12ffdd4 | | | 389 | <button |
| 12ffdd4 | | | 390 | onClick={() => setActiveTab("changes")} |
| 12ffdd4 | | | 391 | className="hover:underline" |
| 12ffdd4 | | | 392 | style={{ |
| 12ffdd4 | | | 393 | color: activeTab === "changes" ? "var(--text-primary)" : "var(--text-muted)", |
| 12ffdd4 | | | 394 | fontWeight: activeTab === "changes" ? 600 : 400, |
| 12ffdd4 | | | 395 | background: "none", |
| 12ffdd4 | | | 396 | border: "none", |
| 12ffdd4 | | | 397 | cursor: "pointer", |
| 12ffdd4 | | | 398 | font: "inherit", |
| 12ffdd4 | | | 399 | fontSize: "inherit", |
| 12ffdd4 | | | 400 | }} |
| 12ffdd4 | | | 401 | > |
| 12ffdd4 | | | 402 | Changes{diffFiles.length > 0 && ` (${diffFiles.length})`} |
| 12ffdd4 | | | 403 | </button> |
| 12ffdd4 | | | 404 | </div> |
| 12ffdd4 | | | 405 | |
| 12ffdd4 | | | 406 | {activeTab === "conversation" && ( |
| 12ffdd4 | | | 407 | <> |
| 12ffdd4 | | | 408 | {activity.map((item) => |
| 12ffdd4 | | | 409 | item.kind === "comment" ? ( |
| 12ffdd4 | | | 410 | <div |
| 12ffdd4 | | | 411 | key={`c-${item.id}`} |
| 12ffdd4 | | | 412 | className="mb-4 pb-4" |
| 12ffdd4 | | | 413 | style={{ borderBottom: "1px solid var(--divide)" }} |
| 12ffdd4 | | | 414 | > |
| 12ffdd4 | | | 415 | <div className="flex items-center justify-between text-xs mb-1"> |
| 12ffdd4 | | | 416 | <span style={{ color: "var(--text-secondary)" }}> |
| 12ffdd4 | | | 417 | {item.author_name} |
| 12ffdd4 | | | 418 | </span> |
| 12ffdd4 | | | 419 | <span style={{ color: "var(--text-faint)" }}> |
| 12ffdd4 | | | 420 | {timeAgo(item.created_at)} |
| 12ffdd4 | | | 421 | </span> |
| 12ffdd4 | | | 422 | </div> |
| 12ffdd4 | | | 423 | {item.file_path && ( |
| 12ffdd4 | | | 424 | <div |
| 12ffdd4 | | | 425 | className="text-xs font-mono mb-1" |
| 12ffdd4 | | | 426 | style={{ color: "var(--text-muted)" }} |
| 12ffdd4 | | | 427 | > |
| 12ffdd4 | | | 428 | {item.file_path} |
| 12ffdd4 | | | 429 | {item.line_number ? `:${item.line_number}` : ""} |
| 12ffdd4 | | | 430 | </div> |
| 12ffdd4 | | | 431 | )} |
| 12ffdd4 | | | 432 | <p |
| 12ffdd4 | | | 433 | className="text-sm whitespace-pre-wrap" |
| 12ffdd4 | | | 434 | style={{ color: "var(--text-secondary)" }} |
| 12ffdd4 | | | 435 | > |
| 12ffdd4 | | | 436 | {item.body} |
| 12ffdd4 | | | 437 | </p> |
| 12ffdd4 | | | 438 | </div> |
| 12ffdd4 | | | 439 | ) : ( |
| 12ffdd4 | | | 440 | <div |
| 12ffdd4 | | | 441 | key={`r-${item.id}`} |
| 12ffdd4 | | | 442 | className="mb-4 pb-4 text-sm" |
| 12ffdd4 | | | 443 | style={{ borderBottom: "1px solid var(--divide)" }} |
| 12ffdd4 | | | 444 | > |
| 12ffdd4 | | | 445 | <span style={{ color: "var(--text-secondary)" }}> |
| 12ffdd4 | | | 446 | {item.reviewer_name} |
| 12ffdd4 | | | 447 | </span>{" "} |
| 12ffdd4 | | | 448 | <span |
| 12ffdd4 | | | 449 | style={{ |
| 12ffdd4 | | | 450 | color: |
| 12ffdd4 | | | 451 | item.status === "approved" |
| 12ffdd4 | | | 452 | ? "var(--status-open-text)" |
| 12ffdd4 | | | 453 | : "var(--status-closed-text)", |
| 12ffdd4 | | | 454 | }} |
| 12ffdd4 | | | 455 | > |
| 12ffdd4 | | | 456 | {item.status === "approved" ? "approved" : "requested changes"} |
| 12ffdd4 | | | 457 | </span> |
| 12ffdd4 | | | 458 | {item.body && ( |
| 12ffdd4 | | | 459 | <p className="mt-1" style={{ color: "var(--text-muted)" }}> |
| 12ffdd4 | | | 460 | {item.body} |
| 12ffdd4 | | | 461 | </p> |
| 12ffdd4 | | | 462 | )} |
| 12ffdd4 | | | 463 | <span className="text-xs" style={{ color: "var(--text-faint)" }}> |
| 12ffdd4 | | | 464 | {" "}{timeAgo(item.created_at)} |
| 12ffdd4 | | | 465 | </span> |
| 12ffdd4 | | | 466 | </div> |
| 12ffdd4 | | | 467 | ) |
| 12ffdd4 | | | 468 | )} |
| 12ffdd4 | | | 469 | |
| 12ffdd4 | | | 470 | {activity.length === 0 && ( |
| 12ffdd4 | | | 471 | <p className="text-sm mb-6" style={{ color: "var(--text-faint)" }}> |
| 12ffdd4 | | | 472 | No activity yet. |
| 135dfe5 | | | 473 | </p> |
| 135dfe5 | | | 474 | )} |
| 135dfe5 | | | 475 | |
| 12ffdd4 | | | 476 | {/* Comment form */} |
| d12933e | | | 477 | {user && diff.status === "open" && ( |
| 12ffdd4 | | | 478 | <form onSubmit={handleComment} className="mt-4"> |
| 12ffdd4 | | | 479 | <textarea |
| 12ffdd4 | | | 480 | value={commentBody} |
| 12ffdd4 | | | 481 | onChange={(e) => setCommentBody(e.target.value)} |
| 12ffdd4 | | | 482 | rows={3} |
| 12ffdd4 | | | 483 | placeholder="Leave a comment..." |
| 12ffdd4 | | | 484 | className="w-full px-2 py-1 text-sm focus:outline-none resize-y mb-2" |
| 12ffdd4 | | | 485 | style={{ |
| 12ffdd4 | | | 486 | backgroundColor: "var(--bg-input)", |
| 12ffdd4 | | | 487 | border: "1px solid var(--border)", |
| 12ffdd4 | | | 488 | color: "var(--text-primary)", |
| 12ffdd4 | | | 489 | }} |
| 12ffdd4 | | | 490 | /> |
| 12ffdd4 | | | 491 | <button |
| 12ffdd4 | | | 492 | type="submit" |
| 12ffdd4 | | | 493 | disabled={commenting || !commentBody.trim()} |
| 12ffdd4 | | | 494 | className="text-sm px-3 py-1" |
| 12ffdd4 | | | 495 | style={{ |
| 12ffdd4 | | | 496 | backgroundColor: "var(--accent)", |
| 12ffdd4 | | | 497 | color: "var(--accent-text)", |
| 12ffdd4 | | | 498 | opacity: commenting || !commentBody.trim() ? 0.5 : 1, |
| 12ffdd4 | | | 499 | border: "none", |
| 12ffdd4 | | | 500 | cursor: commenting ? "default" : "pointer", |
| 12ffdd4 | | | 501 | font: "inherit", |
| 12ffdd4 | | | 502 | fontSize: "inherit", |
| 12ffdd4 | | | 503 | }} |
| 12ffdd4 | | | 504 | > |
| 12ffdd4 | | | 505 | {commenting ? "Commenting..." : "Comment"} |
| 12ffdd4 | | | 506 | </button> |
| 12ffdd4 | | | 507 | </form> |
| 12ffdd4 | | | 508 | )} |
| 12ffdd4 | | | 509 | </> |
| 12ffdd4 | | | 510 | )} |
| 12ffdd4 | | | 511 | |
| 12ffdd4 | | | 512 | {activeTab === "changes" && ( |
| 12ffdd4 | | | 513 | <div> |
| 12ffdd4 | | | 514 | {diffFiles.length === 0 ? ( |
| 12ffdd4 | | | 515 | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| 12ffdd4 | | | 516 | No changes to display. |
| 12ffdd4 | | | 517 | </p> |
| 12ffdd4 | | | 518 | ) : ( |
| 12ffdd4 | | | 519 | diffFiles.map((file) => ( |
| 12ffdd4 | | | 520 | <div key={file.path} className="mb-6"> |
| 12ffdd4 | | | 521 | <div |
| 12ffdd4 | | | 522 | className="text-sm font-mono py-2 px-3" |
| 12ffdd4 | | | 523 | style={{ |
| 12ffdd4 | | | 524 | backgroundColor: "var(--bg-inset)", |
| 12ffdd4 | | | 525 | border: "1px solid var(--border)", |
| 12ffdd4 | | | 526 | borderBottom: "none", |
| 12ffdd4 | | | 527 | color: "var(--text-secondary)", |
| 12ffdd4 | | | 528 | }} |
| 12ffdd4 | | | 529 | > |
| 12ffdd4 | | | 530 | {file.path} |
| 12ffdd4 | | | 531 | </div> |
| 12ffdd4 | | | 532 | <div |
| 12ffdd4 | | | 533 | className="overflow-x-auto" |
| 12ffdd4 | | | 534 | style={{ border: "1px solid var(--border)" }} |
| 12ffdd4 | | | 535 | > |
| 12ffdd4 | | | 536 | <table className="w-full text-sm font-mono" style={{ borderCollapse: "collapse" }}> |
| 12ffdd4 | | | 537 | <tbody> |
| 12ffdd4 | | | 538 | {file.hunks.map((hunk, hi) => ( |
| 12ffdd4 | | | 539 | <> |
| 12ffdd4 | | | 540 | <tr key={`h-${hi}`}> |
| 12ffdd4 | | | 541 | <td |
| 12ffdd4 | | | 542 | colSpan={3} |
| 12ffdd4 | | | 543 | className="text-xs py-1 px-3" |
| 12ffdd4 | | | 544 | style={{ |
| 12ffdd4 | | | 545 | backgroundColor: "var(--bg-inset)", |
| 12ffdd4 | | | 546 | color: "var(--text-faint)", |
| 12ffdd4 | | | 547 | }} |
| 12ffdd4 | | | 548 | > |
| 12ffdd4 | | | 549 | {hunk.header} |
| 12ffdd4 | | | 550 | </td> |
| 12ffdd4 | | | 551 | </tr> |
| 12ffdd4 | | | 552 | {hunk.lines.map((line, li) => ( |
| 12ffdd4 | | | 553 | <tr |
| 12ffdd4 | | | 554 | key={`${hi}-${li}`} |
| 12ffdd4 | | | 555 | style={{ |
| 12ffdd4 | | | 556 | backgroundColor: |
| 12ffdd4 | | | 557 | line.type === "add" |
| 12ffdd4 | | | 558 | ? "var(--diff-add-bg, rgba(46,160,67,0.1))" |
| 12ffdd4 | | | 559 | : line.type === "del" |
| 12ffdd4 | | | 560 | ? "var(--diff-del-bg, rgba(248,81,73,0.1))" |
| 12ffdd4 | | | 561 | : "transparent", |
| 12ffdd4 | | | 562 | }} |
| 12ffdd4 | | | 563 | > |
| 12ffdd4 | | | 564 | <td |
| 12ffdd4 | | | 565 | className="text-right select-none px-2 py-0 w-10" |
| 12ffdd4 | | | 566 | style={{ |
| 12ffdd4 | | | 567 | color: "var(--text-faint)", |
| 12ffdd4 | | | 568 | borderRight: "1px solid var(--divide)", |
| 12ffdd4 | | | 569 | fontSize: "0.75rem", |
| 12ffdd4 | | | 570 | }} |
| 12ffdd4 | | | 571 | > |
| 12ffdd4 | | | 572 | {line.oldNum ?? ""} |
| 12ffdd4 | | | 573 | </td> |
| 12ffdd4 | | | 574 | <td |
| 12ffdd4 | | | 575 | className="text-right select-none px-2 py-0 w-10" |
| 12ffdd4 | | | 576 | style={{ |
| 12ffdd4 | | | 577 | color: "var(--text-faint)", |
| 12ffdd4 | | | 578 | borderRight: "1px solid var(--divide)", |
| 12ffdd4 | | | 579 | fontSize: "0.75rem", |
| 12ffdd4 | | | 580 | }} |
| 12ffdd4 | | | 581 | > |
| 12ffdd4 | | | 582 | {line.newNum ?? ""} |
| 12ffdd4 | | | 583 | </td> |
| 12ffdd4 | | | 584 | <td |
| 12ffdd4 | | | 585 | className="pl-3 py-0 whitespace-pre" |
| 12ffdd4 | | | 586 | style={{ |
| 12ffdd4 | | | 587 | color: |
| 12ffdd4 | | | 588 | line.type === "add" |
| 12ffdd4 | | | 589 | ? "var(--diff-add-text, #3fb950)" |
| 12ffdd4 | | | 590 | : line.type === "del" |
| 12ffdd4 | | | 591 | ? "var(--diff-del-text, #f85149)" |
| 12ffdd4 | | | 592 | : "var(--text-secondary)", |
| 12ffdd4 | | | 593 | }} |
| 12ffdd4 | | | 594 | > |
| 12ffdd4 | | | 595 | {line.type === "add" ? "+" : line.type === "del" ? "-" : " "} |
| 12ffdd4 | | | 596 | {line.content} |
| 12ffdd4 | | | 597 | </td> |
| 12ffdd4 | | | 598 | </tr> |
| 12ffdd4 | | | 599 | ))} |
| 12ffdd4 | | | 600 | </> |
| 12ffdd4 | | | 601 | ))} |
| 12ffdd4 | | | 602 | </tbody> |
| 12ffdd4 | | | 603 | </table> |
| 12ffdd4 | | | 604 | </div> |
| 12ffdd4 | | | 605 | </div> |
| 12ffdd4 | | | 606 | )) |
| 12ffdd4 | | | 607 | )} |
| 12ffdd4 | | | 608 | </div> |
| 135dfe5 | | | 609 | )} |
| 3e3af55 | | | 610 | </div> |
| 3e3af55 | | | 611 | ); |
| 3e3af55 | | | 612 | } |