import { useState, useEffect } from 'react' import { Link, useParams, useNavigate } from 'react-router-dom' import { format } from 'date-fns' import { ArrowLeft, FilePlus, FileMinus, FileEdit, GitCommit } from 'lucide-react' import { Skeleton } from '@/components/ui/skeleton' import { getCommit } from '@/lib/gitApi' import type { GitCommitDetail } from '@/lib/gitApi' import { useRepo } from '@/lib/repo' const statusIcon = { added: , deleted: , modified: , renamed: , } const statusLabel = { added: 'A', deleted: 'D', modified: 'M', renamed: 'R', } // Commit detail page (/:repo/commit/:hash). Shows commit metadata, full message, // parent links, and the list of files changed with add/modify/delete/rename status. export function CommitPage() { const { hash } = useParams<{ hash: string }>() const navigate = useNavigate() const repo = useRepo() const [commit, setCommit] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { setLoading(true) setError(null) getCommit(hash!) .then(setCommit) .catch((e: Error) => setError(e.message)) .finally(() => setLoading(false)) }, [hash]) if (loading) return if (error) { return (
Failed to load commit: {error}
) } if (!commit) return null const date = new Date(commit.date) return (
{/* Header */}

{commit.message}

{/* Full message body (if multi-line) */} {commit.fullMessage.includes('\n') && (
            {commit.fullMessage.split('\n').slice(1).join('\n').trim()}
          
)}
{commit.authorName} {commit.authorEmail && ( <{commit.authorEmail}> )} {format(date, 'PPP')}
commit{' '} {commit.hash} {commit.parents.map((p) => ( parent{' '} {p.slice(0, 7)} ))}
{/* Changed files */}

{commit.files.length} file{commit.files.length !== 1 ? 's' : ''} changed

{commit.files.length === 0 && (

No file changes.

)} {commit.files.map((file) => (
{statusIcon[file.status]} {file.status === 'renamed' ? ( <> {file.oldPath} {' → '} {file.path} ) : ( file.path )} {statusLabel[file.status]}
))}
) } function CommitPageSkeleton() { return (
{Array.from({ length: 5 }).map((_, i) => (
))}
) }