| 1 | "use client"; |
| 2 | |
| 3 | import { useParams, usePathname } from "next/navigation"; |
| 4 | import { FileTreeSidebar } from "@/app/components/file-tree-sidebar"; |
| 5 | |
| 6 | export default function RepoLayout({ |
| 7 | children, |
| 8 | }: { |
| 9 | children: React.ReactNode; |
| 10 | }) { |
| 11 | const { owner, repo } = useParams<{ owner: string; repo: string }>(); |
| 12 | const pathname = usePathname(); |
| 13 | |
| 14 | const prefix = `/${owner}/${repo}/`; |
| 15 | const rest = pathname?.startsWith(prefix) ? pathname.slice(prefix.length) : ""; |
| 16 | const isCodeBrowsing = rest.startsWith("blob/") || rest.startsWith("tree/"); |
| 17 | |
| 18 | // Extract ref from URL (e.g., blob/main/... or tree/main/...) |
| 19 | const refMatch = rest.match(/^(?:blob|tree)\/([^/]+)/); |
| 20 | const ref = refMatch?.[1] ?? "main"; |
| 21 | |
| 22 | if (!isCodeBrowsing) { |
| 23 | return <>{children}</>; |
| 24 | } |
| 25 | |
| 26 | return ( |
| 27 | <div className="flex"> |
| 28 | <FileTreeSidebar owner={owner} repo={repo} refName={ref} /> |
| 29 | <div className="flex-1 min-w-0 flex justify-center"> |
| 30 | <div className="w-full max-w-4xl"> |
| 31 | {children} |
| 32 | </div> |
| 33 | </div> |
| 34 | </div> |
| 35 | ); |
| 36 | } |
| 37 | |