mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
suspense all the things
This commit is contained in:
parent
dd107b53de
commit
c768b15bd7
4 changed files with 184 additions and 134 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { Suspense } from "react";
|
||||
import { notFound } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { getRepository, getRepoFile, getRepoBranches } from "@/actions/repositories";
|
||||
import { CodeViewer } from "@/components/code-viewer";
|
||||
import { BranchSelector } from "@/components/branch-selector";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Lock, Globe, ChevronRight, Home, FileCode } from "lucide-react";
|
||||
import { Lock, Globe, ChevronRight, Home, FileCode, Loader2 } from "lucide-react";
|
||||
|
||||
const LANGUAGE_MAP: Record<string, string> = {
|
||||
ts: "typescript",
|
||||
|
|
@ -32,30 +33,40 @@ function getLanguage(filename: string): string {
|
|||
return LANGUAGE_MAP[ext] || "text";
|
||||
}
|
||||
|
||||
export default async function BlobPage({ params }: { params: Promise<{ username: string; repo: string; path: string[] }> }) {
|
||||
const { username, repo: repoName, path: pathSegments } = await params;
|
||||
const branch = pathSegments[0];
|
||||
const filePath = pathSegments.slice(1).join("/");
|
||||
|
||||
const repo = await getRepository(username, repoName);
|
||||
|
||||
if (!repo) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const [file, branches] = await Promise.all([
|
||||
getRepoFile(username, repoName, branch, filePath),
|
||||
getRepoBranches(username, repoName),
|
||||
]);
|
||||
async function FileContent({ username, repoName, branch, filePath }: { username: string; repoName: string; branch: string; filePath: string }) {
|
||||
const file = await getRepoFile(username, repoName, branch, filePath);
|
||||
|
||||
if (!file) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const fileName = filePath.split("/").pop() || "";
|
||||
const language = getLanguage(fileName);
|
||||
|
||||
return <CodeViewer content={file.content} language={language} showLineNumbers />;
|
||||
}
|
||||
|
||||
function CodeSkeleton() {
|
||||
return (
|
||||
<div className="p-4 min-h-[400px] flex items-center justify-center">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default async function BlobPage({ params }: { params: Promise<{ username: string; repo: string; path: string[] }> }) {
|
||||
const { username, repo: repoName, path: pathSegments } = await params;
|
||||
const branch = pathSegments[0];
|
||||
const filePath = pathSegments.slice(1).join("/");
|
||||
|
||||
const [repo, branches] = await Promise.all([getRepository(username, repoName), getRepoBranches(username, repoName)]);
|
||||
|
||||
if (!repo) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const pathParts = filePath.split("/").filter(Boolean);
|
||||
const fileName = pathParts[pathParts.length - 1];
|
||||
const language = getLanguage(fileName);
|
||||
const lineCount = file.content.split("\n").length;
|
||||
|
||||
return (
|
||||
<div className="container px-4 py-6">
|
||||
|
|
@ -86,12 +97,7 @@ export default async function BlobPage({ params }: { params: Promise<{ username:
|
|||
|
||||
<div className="border border-border rounded-lg overflow-hidden">
|
||||
<div className="flex items-center gap-2 px-4 py-3 bg-card border-b border-border">
|
||||
<BranchSelector
|
||||
branches={branches}
|
||||
currentBranch={branch}
|
||||
username={username}
|
||||
repoName={repoName}
|
||||
/>
|
||||
<BranchSelector branches={branches} currentBranch={branch} username={username} repoName={repoName} />
|
||||
</div>
|
||||
<nav className="flex items-center gap-1 px-4 py-2 bg-muted/30 border-b border-border text-sm">
|
||||
<Link href={`/${username}/${repoName}`} className="text-accent hover:underline flex items-center gap-1">
|
||||
|
|
@ -115,11 +121,13 @@ export default async function BlobPage({ params }: { params: Promise<{ username:
|
|||
<div className="flex items-center justify-between px-4 py-2 bg-muted/30 border-b border-border">
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<FileCode className="h-4 w-4" />
|
||||
<span>{lineCount} lines</span>
|
||||
<span>{fileName}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CodeViewer content={file.content} language={language} showLineNumbers />
|
||||
<Suspense fallback={<CodeSkeleton />}>
|
||||
<FileContent username={username} repoName={repoName} branch={branch} filePath={filePath} />
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue