web/app/%5Bowner%5D/%5Brepo%5D/layout.tsxblame
View source
4dfd09b1"use client";
4dfd09b2
4dfd09b3import { useParams, usePathname } from "next/navigation";
4dfd09b4import { FileTreeSidebar } from "@/app/components/file-tree-sidebar";
4dfd09b5
4dfd09b6export default function RepoLayout({
4dfd09b7 children,
4dfd09b8}: {
4dfd09b9 children: React.ReactNode;
4dfd09b10}) {
4dfd09b11 const { owner, repo } = useParams<{ owner: string; repo: string }>();
4dfd09b12 const pathname = usePathname();
4dfd09b13
4dfd09b14 const prefix = `/${owner}/${repo}/`;
4dfd09b15 const rest = pathname?.startsWith(prefix) ? pathname.slice(prefix.length) : "";
4dfd09b16 const isCodeBrowsing = rest.startsWith("blob/") || rest.startsWith("tree/");
4dfd09b17
4dfd09b18 // Extract ref from URL (e.g., blob/main/... or tree/main/...)
4dfd09b19 const refMatch = rest.match(/^(?:blob|tree)\/([^/]+)/);
4dfd09b20 const ref = refMatch?.[1] ?? "main";
4dfd09b21
4dfd09b22 if (!isCodeBrowsing) {
4dfd09b23 return <>{children}</>;
4dfd09b24 }
4dfd09b25
4dfd09b26 return (
4dfd09b27 <div className="flex">
4dfd09b28 <FileTreeSidebar owner={owner} repo={repo} refName={ref} />
4dfd09b29 <div className="flex-1 min-w-0 flex justify-center">
4dfd09b30 <div className="w-full max-w-4xl">
4dfd09b31 {children}
4dfd09b32 </div>
4dfd09b33 </div>
4dfd09b34 </div>
4dfd09b35 );
4dfd09b36}