2024-09-26 03:12:20 +00:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { CodePreview } from "./codePreview";
|
|
|
|
|
import { SearchResultFile, SearchResultFileMatch } from "@/lib/types";
|
2024-10-16 00:33:44 +00:00
|
|
|
import { base64Decode } from "@/lib/utils";
|
2024-09-26 03:12:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
interface FileMatchProps {
|
|
|
|
|
match: SearchResultFileMatch;
|
|
|
|
|
file: SearchResultFile;
|
|
|
|
|
onOpen: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileMatch = ({
|
|
|
|
|
match,
|
|
|
|
|
file,
|
|
|
|
|
onOpen,
|
|
|
|
|
}: FileMatchProps) => {
|
|
|
|
|
const content = useMemo(() => {
|
2024-10-16 00:33:44 +00:00
|
|
|
return base64Decode(match.Content);
|
2024-09-26 03:12:20 +00:00
|
|
|
}, [match.Content]);
|
|
|
|
|
|
|
|
|
|
// If it's just the title, don't show a code preview
|
|
|
|
|
if (match.FileName) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
tabIndex={0}
|
2024-10-30 16:32:05 +00:00
|
|
|
className="cursor-pointer focus:ring-inset focus:ring-4 bg-white dark:bg-[#282c34]"
|
2024-09-26 03:12:20 +00:00
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key !== "Enter") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
onOpen();
|
|
|
|
|
}}
|
|
|
|
|
onClick={onOpen}
|
|
|
|
|
>
|
|
|
|
|
<CodePreview
|
|
|
|
|
content={content}
|
|
|
|
|
language={file.Language}
|
|
|
|
|
ranges={match.Ranges}
|
|
|
|
|
lineOffset={match.ContentStart.LineNumber - 1}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|