Add diff expansion controls with ContentDiffViewer and CodePreview components

This commit is contained in:
Chris Scott committed 2025-12-26 18:07:33 -05:00
1 parent 55b6ab3c87
commit 4fd658fc7d
11 files changed
+549 -53

No files matched your search

+20 -24
View File
@@ -1,38 +1,34 @@
import { useState } from 'react'
import type { components } from '@/api/opencode-types'
import { getRelativePath } from './FileToolRender'
type PatchPart = components['schemas']['PatchPart']
type PatchPartType = components['schemas']['PatchPart']
interface PatchPartProps {
part: PatchPart
part: PatchPartType
onFileClick?: (filePath: string) => void
}
export function PatchPart({ part }: PatchPartProps) {
const [expanded, setExpanded] = useState(true)
export function PatchPart({ part, onFileClick }: PatchPartProps) {
return (
<div className="border border-zinc-800 rounded-lg overflow-hidden my-2">
<button
onClick={() => setExpanded(!expanded)}
className="w-full px-4 py-2 bg-zinc-900 hover:bg-zinc-800 text-left flex items-center justify-between text-sm"
>
<div className="border border-border rounded-lg overflow-hidden my-2">
<div className="px-3 py-1.5 bg-card flex items-center justify-between text-sm">
<span className="font-medium">
File Changes ({part.files.length} file{part.files.length !== 1 ? 's' : ''})
</span>
<span className="text-zinc-400 text-xs font-mono">{part.hash.slice(0, 8)}</span>
</button>
<span className="text-muted-foreground text-xs font-mono">{part.hash.slice(0, 8)}</span>
</div>
{expanded && (
<div className="bg-zinc-950 p-4">
<div className="space-y-2">
{part.files.map((file, index) => (
<div key={index} className="text-sm">
<div className="font-mono text-zinc-400 mb-1">{file}</div>
</div>
))}
<div className="bg-card px-3 py-2 space-y-1">
{part.files.map((file, index) => (
<div
key={index}
className="text-xs font-mono text-blue-600 dark:text-blue-400 hover:underline cursor-pointer"
onClick={() => onFileClick?.(file)}
>
{getRelativePath(file)}
</div>
</div>
)}
))}
</div>
</div>
)
}
}