import { useEffect, useState } from 'react'; import { Button, Collapse, Drawer, Icon, Intent, NonIdealState, Spinner, Tag, Tooltip } from '@blueprintjs/core'; import { html as diff2htmlHtml } from 'diff2html'; import 'diff2html/bundles/css/diff2html.min.css'; import { getCommitDetail, type CommitDetail, type CommitFile } from '../api/opcApi'; interface Props { hash: string | null; onClose: () => void; } function fileStatusIntent(status: string): Intent { if (status === 'added') return Intent.SUCCESS; if (status === 'deleted') return Intent.DANGER; if (status === 'renamed') return Intent.WARNING; return Intent.NONE; } function fileStatusIcon(status: string): string { if (status === 'added') return 'plus'; if (status === 'deleted') return 'minus'; if (status === 'renamed') return 'arrow-right'; return 'edit'; } function FileDiff({ file }: { file: CommitFile }) { const [open, setOpen] = useState(true); const diffHtml = file.patch ? diff2htmlHtml(file.patch, { drawFileList: false, matching: 'lines', outputFormat: 'line-by-line', renderNothingWhenEmpty: true, }) : ''; const displayPath = file.status === 'renamed' && file.oldPath && file.oldPath !== file.path ? `${file.oldPath} → ${file.path}` : file.path; return (
{detail.shortHash}
{detail.subject}
) : 'Commit Diff'
}
size="70%"
position="right"
className="git-commit-drawer"
>
{/* Scrollable body */}
navigator.clipboard.writeText(detail.hash)}
style={{ cursor: 'pointer' }}
>
{detail.shortHash}
{detail.body.trim()}
)}
{/* Per-file diffs */}
{detail.files.length === 0 ? (