import { Folder, File } from 'lucide-react' import { Link } from 'react-router-dom' import { formatDistanceToNow } from 'date-fns' import { Skeleton } from '@/components/ui/skeleton' import { useRepo } from '@/lib/repo' import type { GitTreeEntry } from '@/lib/gitApi' interface FileTreeProps { entries: GitTreeEntry[] path: string loading?: boolean onNavigate: (entry: GitTreeEntry) => void onNavigateUp: () => void } // Directory listing table for the code browser. Shows each entry's icon, // name, last-commit message (linked to commit detail), and relative date. export function FileTree({ entries, path, loading, onNavigate, onNavigateUp }: FileTreeProps) { // Directories first, then files — each group alphabetical const sorted = [...entries].sort((a, b) => { if (a.type !== b.type) return a.type === 'tree' ? -1 : 1 return a.name.localeCompare(b.name) }) if (loading) return return (
{path && ( )} {sorted.map((entry) => ( ))}
..
) } function FileTreeRow({ entry, onNavigate, }: { entry: GitTreeEntry onNavigate: (entry: GitTreeEntry) => void }) { const isDir = entry.type === 'tree' const repo = useRepo() return ( onNavigate(entry)} > {isDir ? ( ) : ( )} {entry.name} {entry.lastCommit && ( e.stopPropagation()} > {entry.lastCommit.message} )} {entry.lastCommit && formatDistanceToNow(new Date(entry.lastCommit.date), { addSuffix: true })} ) } function FileTreeSkeleton() { return (
{Array.from({ length: 8 }).map((_, i) => (
))}
) }