2025-06-06 19:38:16 +00:00
|
|
|
import { getRepoInfoByName } from "@/actions";
|
2025-07-14 23:07:09 +00:00
|
|
|
import { PathHeader } from "@/app/[domain]/components/pathHeader";
|
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
|
|
|
|
import { getFileSource } from "@/features/search/fileSourceApi";
|
|
|
|
|
import { cn, getCodeHostInfoForRepo, isServiceError } from "@/lib/utils";
|
2025-06-06 19:38:16 +00:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import { PureCodePreviewPanel } from "./pureCodePreviewPanel";
|
|
|
|
|
|
2025-07-14 23:07:09 +00:00
|
|
|
interface CodePreviewPanelProps {
|
|
|
|
|
path: string;
|
|
|
|
|
repoName: string;
|
|
|
|
|
revisionName?: string;
|
|
|
|
|
domain: string;
|
|
|
|
|
}
|
2025-06-06 19:38:16 +00:00
|
|
|
|
2025-07-14 23:07:09 +00:00
|
|
|
export const CodePreviewPanel = async ({ path, repoName, revisionName, domain }: CodePreviewPanelProps) => {
|
|
|
|
|
const [fileSourceResponse, repoInfoResponse] = await Promise.all([
|
|
|
|
|
getFileSource({
|
2025-06-06 19:38:16 +00:00
|
|
|
fileName: path,
|
|
|
|
|
repository: repoName,
|
2025-07-14 23:07:09 +00:00
|
|
|
branch: revisionName,
|
|
|
|
|
}, domain),
|
|
|
|
|
getRepoInfoByName(repoName, domain),
|
|
|
|
|
]);
|
2025-06-06 19:38:16 +00:00
|
|
|
|
2025-07-14 23:07:09 +00:00
|
|
|
if (isServiceError(fileSourceResponse) || isServiceError(repoInfoResponse)) {
|
2025-06-06 19:38:16 +00:00
|
|
|
return <div>Error loading file source</div>
|
|
|
|
|
}
|
2025-05-28 23:08:42 +00:00
|
|
|
|
2025-07-14 23:07:09 +00:00
|
|
|
const codeHostInfo = getCodeHostInfoForRepo({
|
|
|
|
|
codeHostType: repoInfoResponse.codeHostType,
|
|
|
|
|
name: repoInfoResponse.name,
|
|
|
|
|
displayName: repoInfoResponse.displayName,
|
|
|
|
|
webUrl: repoInfoResponse.webUrl,
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-28 23:08:42 +00:00
|
|
|
return (
|
2025-06-06 19:38:16 +00:00
|
|
|
<>
|
|
|
|
|
<div className="flex flex-row py-1 px-2 items-center justify-between">
|
|
|
|
|
<PathHeader
|
|
|
|
|
path={path}
|
|
|
|
|
repo={{
|
|
|
|
|
name: repoName,
|
|
|
|
|
codeHostType: repoInfoResponse.codeHostType,
|
|
|
|
|
displayName: repoInfoResponse.displayName,
|
|
|
|
|
webUrl: repoInfoResponse.webUrl,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{(fileSourceResponse.webUrl && codeHostInfo) && (
|
|
|
|
|
<a
|
|
|
|
|
href={fileSourceResponse.webUrl}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className="flex flex-row items-center gap-2 px-2 py-0.5 rounded-md flex-shrink-0"
|
|
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
src={codeHostInfo.icon}
|
|
|
|
|
alt={codeHostInfo.codeHostName}
|
|
|
|
|
className={cn('w-4 h-4 flex-shrink-0', codeHostInfo.iconClassName)}
|
2025-05-28 23:08:42 +00:00
|
|
|
/>
|
2025-06-06 19:38:16 +00:00
|
|
|
<span className="text-sm font-medium">Open in {codeHostInfo.codeHostName}</span>
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<Separator />
|
|
|
|
|
<PureCodePreviewPanel
|
2025-06-17 22:58:04 +00:00
|
|
|
source={fileSourceResponse.source}
|
2025-06-06 19:38:16 +00:00
|
|
|
language={fileSourceResponse.language}
|
|
|
|
|
repoName={repoName}
|
|
|
|
|
path={path}
|
|
|
|
|
revisionName={revisionName ?? 'HEAD'}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2025-05-28 23:08:42 +00:00
|
|
|
)
|
2025-06-06 19:38:16 +00:00
|
|
|
}
|