Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GuideFileDiff.tsx

45 lines1.4 KB

1import {
2 cloneFileDiffMetadata,
3 type FileDiffContentsLoader,
4 type FileDiffMetadata,
5} from "@pierre/diffs";
6import { FileDiff } from "@pierre/diffs/react";
7import { useMemo } from "react";
8​
9import { useTheme } from "~/hooks/useTheme";
10import { resolveDiffThemeName } from "~/lib/diffRendering";
11import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
12​
13import { DIFF_VIEW_UNSAFE_CSS } from "../../diffs/StyledDiffCodeView";
14​
15export function GuideFileDiff({
16 file,
17 loadDiffFiles,
18}: {
19 file: FileDiffMetadata;
20 loadDiffFiles: FileDiffContentsLoader;
21}) {
22 const { resolvedTheme } = useTheme();
23 // Loading the unchanged lines rewrites the diff it is given; the excerpts read the same file
24 // as a patch, so this view expands a copy of its own.
25 const expandable = useMemo(() => cloneFileDiffMetadata(file), [file]);
26 const options = useMemo(
27 () => ({
28 diffStyle: "unified" as const,
29 lineDiffType: "none" as const,
30 overflow: "scroll" as const,
31 disableFileHeader: true,
32 theme: resolveDiffThemeName(resolvedTheme),
33 themeType: resolvedTheme,
34 preferredHighlighter: PREFERRED_HIGHLIGHTER,
35 unsafeCSS: DIFF_VIEW_UNSAFE_CSS,
36 loadDiffFiles,
37 }),
38 [loadDiffFiles, resolvedTheme],
39 );
40 return (
41 <div className="border-t border-border/60">
42 <FileDiff fileDiff={expandable} options={options} />
43 </div>
44 );