-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-content.tsx
More file actions
167 lines (159 loc) · 5.37 KB
/
file-content.tsx
File metadata and controls
167 lines (159 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"use client";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { vscDarkPlus } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { oneLight } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { useTheme } from "next-themes";
import { ReviewButton } from "./review-button";
interface FileContentProps {
selectedFile: string;
fileContent: string;
highlightedLines: number[];
lineComments: Record<number, string>;
onLineClick: (lineNumber: number, e: React.MouseEvent) => void;
setReview: (review: string) => void;
showDialog: boolean;
selectedLine: number | null;
onCloseDialog: () => void;
}
export function FileContent({
selectedFile,
fileContent,
highlightedLines,
lineComments,
onLineClick,
setReview,
showDialog,
selectedLine,
onCloseDialog,
}: FileContentProps) {
const { theme } = useTheme();
console.log(lineComments);
const getLanguageFromFileName = (fileName: string) => {
const extension = fileName.split(".").pop()?.toLowerCase();
switch (extension) {
case "ts":
case "tsx":
return "typescript";
case "js":
case "jsx":
return "javascript";
case "css":
return "css";
case "html":
return "html";
case "json":
return "json";
case "md":
return "markdown";
default:
return "text";
}
};
const lineProps = (lineNumber: number) => {
const isHighlighted = highlightedLines.includes(lineNumber);
const comment = lineComments[lineNumber];
console.log("Line number:", lineNumber, "Comment:", comment);
return {
style: {
display: "block",
backgroundColor: isHighlighted
? theme === "dark" ? "rgba(255, 255, 0, 0.2)" : "rgba(255, 215, 0, 0.15)"
: "transparent",
borderLeft: isHighlighted ? "3px solid #ffd700" : "none",
paddingLeft: isHighlighted ? "5px" : "0",
transition: "background-color 0.2s ease",
cursor: isHighlighted ? "pointer" : "default",
},
onClick: (e: React.MouseEvent) => {
if (isHighlighted && comment) {
console.log("Clicking line:", lineNumber, "Comment:", comment);
onLineClick(lineNumber, e);
}
},
};
};
return (
<>
<div className='h-full bg-card flex flex-col'>
<div className='flex items-center justify-between p-4 border-b border-border'>
<div className='flex items-center gap-2'>
<span className='text-sm font-medium text-foreground'>{selectedFile || 'No file selected'}</span>
<span className='text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground'>{selectedFile ? getLanguageFromFileName(selectedFile) : ''}</span>
</div>
{selectedFile && (
<ReviewButton
selectedFile={selectedFile}
fileContent={fileContent}
setReview={setReview}
/>
)}
</div>
<div className='flex-1 overflow-hidden'>
<ScrollArea className='h-[calc(100vh-120px)]'>
{selectedFile ? (
<div className='relative'>
<div className='overflow-x-auto bg-card'>
<SyntaxHighlighter
language={getLanguageFromFileName(selectedFile)}
customStyle={{
margin: 0,
padding: "1rem",
fontSize: "0.875rem",
lineHeight: "1.5",
background: "transparent",
maxWidth: "100%",
overflowX: "auto",
whiteSpace: "pre-wrap",
wordBreak: "break-word",
wordWrap: "break-word",
}}
showLineNumbers
wrapLines={true}
wrapLongLines={true}
lineProps={lineProps}
style={theme === "dark" ? vscDarkPlus : oneLight}
>
{fileContent}
</SyntaxHighlighter>
</div>
</div>
) : (
<div className='h-full flex items-center justify-center text-muted-foreground'>
<p>Select a file from the list to view its content</p>
</div>
)}
</ScrollArea>
</div>
</div>
<Dialog open={showDialog} onOpenChange={onCloseDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle>Line {selectedLine}</DialogTitle>
</DialogHeader>
<div className='prose dark:prose-invert max-w-none text-sm'>
<p className='whitespace-pre-wrap'>
{selectedLine
? (() => {
console.log("Dialog - Selected Line:", selectedLine);
console.log("Dialog - Line Comments:", lineComments);
console.log(
"Dialog - Comment for selected line:",
lineComments[selectedLine]
);
return lineComments[selectedLine];
})()
: ""}
</p>
</div>
</DialogContent>
</Dialog>
</>
);
}