File tree Expand file tree Collapse file tree 7 files changed +364
-12
lines changed
blocks/interview/question-attempts Expand file tree Collapse file tree 7 files changed +364
-12
lines changed Original file line number Diff line number Diff line change 48
48
"react-katex" : " ^3.0.1" ,
49
49
"react-markdown" : " ^9.0.1" ,
50
50
"react-router-dom" : " ^6.26.2" ,
51
+ "react-syntax-highlighter" : " ^15.6.1" ,
51
52
"rehype-katex" : " ^7.0.1" ,
52
53
"remark-gfm" : " ^4.0.0" ,
53
54
"remark-math" : " ^6.0.0" ,
68
69
"@types/node" : " ^22.5.5" ,
69
70
"@types/react" : " ^18.3.3" ,
70
71
"@types/react-dom" : " ^18.3.0" ,
72
+ "@types/react-syntax-highlighter" : " ^15.5.13" ,
71
73
"@types/ws" : " ^8.5.12" ,
72
74
"@vitejs/plugin-react-swc" : " ^3.5.0" ,
73
75
"autoprefixer" : " ^10.4.20" ,
Original file line number Diff line number Diff line change
1
+ import { Check , Copy } from 'lucide-react' ;
2
+ import { FC , useState } from 'react' ;
3
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' ;
4
+ import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism' ;
5
+
6
+ import { Button } from '@/components/ui/button' ;
7
+
8
+ type ICodeProps = {
9
+ code : string ;
10
+ language : string ;
11
+ } ;
12
+
13
+ const defaultCopyCodeText = 'Copy Code' ;
14
+
15
+ export const CodeViewer : FC < ICodeProps > = ( { code, language } ) => {
16
+ const [ copyCodeText , setCopyCodeText ] = useState ( 'Copy Code' ) ;
17
+
18
+ const onCopy = ( ) => {
19
+ navigator . clipboard . writeText ( code ) ;
20
+ setCopyCodeText ( 'Copied!' ) ;
21
+ setTimeout ( ( ) => {
22
+ setCopyCodeText ( defaultCopyCodeText ) ;
23
+ } , 3000 ) ;
24
+ } ;
25
+
26
+ return (
27
+ < div className = 'flex size-full flex-col overflow-y-auto rounded-md' >
28
+ < div className = 'bg-muted-foreground text-muted dark:bg-muted dark:text-muted-foreground flex w-full items-center justify-between px-3 py-2' >
29
+ < span className = 'text-sm font-medium' > { language } </ span >
30
+ < Button
31
+ variant = 'secondary'
32
+ size = 'sm'
33
+ onClick = { onCopy }
34
+ className = 'border-border dark:text-muted-foreground text-muted hover:text-primary dark:hover:bg-primary/10 group flex items-center gap-2 bg-inherit disabled:cursor-not-allowed'
35
+ >
36
+ < span > { copyCodeText } </ span >
37
+ { copyCodeText === defaultCopyCodeText ? (
38
+ < Copy className = 'size-3' />
39
+ ) : (
40
+ < Check className = 'size-3 text-green-400 group-hover:text-green-700' />
41
+ ) }
42
+ </ Button >
43
+ </ div >
44
+ < SyntaxHighlighter
45
+ customStyle = { {
46
+ borderRadius : '0 0 0.3em 0.3em' ,
47
+ margin : 0 ,
48
+ minHeight : '100px' ,
49
+ } }
50
+ PreTag = 'div'
51
+ style = { oneDark }
52
+ language = { language }
53
+ >
54
+ { code }
55
+ </ SyntaxHighlighter >
56
+ </ div >
57
+ ) ;
58
+ } ;
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import {
11
11
} from '@/components/ui/dialog' ;
12
12
import { IQuestionAttempt } from '@/types/question-types' ;
13
13
14
+ import { CodeViewer } from './code-viewer' ;
15
+
14
16
type AttemptDetailsPaneProps = {
15
17
triggerText : string ;
16
18
} & IQuestionAttempt ;
@@ -29,14 +31,18 @@ export const AttemptDetailsDialog: FC<PropsWithChildren<AttemptDetailsPaneProps>
29
31
) : (
30
32
< DialogTrigger > { triggerText } </ DialogTrigger >
31
33
) }
32
- < DialogContent >
34
+ < DialogContent className = 'border-border text-primary' >
33
35
< DialogHeader >
34
- < DialogTitle >
36
+ < DialogTitle className = '' >
35
37
Attempt < span className = 'font-mono' > { attemptId } </ span >
36
38
</ DialogTitle >
37
39
</ DialogHeader >
38
- < DialogDescription />
39
- < DialogFooter />
40
+ < DialogDescription >
41
+ < CodeViewer { ...{ code, language } } />
42
+ </ DialogDescription >
43
+ < DialogFooter >
44
+ < span className = 'font-base text-sm' > Attempted at: { triggerText } </ span >
45
+ </ DialogFooter >
40
46
</ DialogContent >
41
47
</ Dialog >
42
48
) ;
Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ export function QuestionAttemptsTable<TValue>({
74
74
75
75
return (
76
76
< div className = 'relative flex max-h-full w-full grow flex-col' >
77
- < div className = 'flex items-center py-4 ' >
77
+ < div className = 'flex items-center pb-4 pt-2 ' >
78
78
< div className = 'flex flex-col gap-1' >
79
- < label className = 'text-sm font-medium' > Filter by Language</ label >
79
+ < label className = 'ml-0.5 text-sm font-medium' > Filter by Language</ label >
80
80
< ComboboxMulti
81
81
setValuesCallback = { setLanguages }
82
82
options = { Array . from ( new Set ( data . map ( ( v ) => v . language ) ) ) . map ( ( v ) => ( {
@@ -116,7 +116,7 @@ export function QuestionAttemptsTable<TValue>({
116
116
</ TableHeader >
117
117
</ Table >
118
118
</ div >
119
- < ScrollArea className = 'size-full overflow-x-auto border-x' >
119
+ < ScrollArea className = 'border-border size-full overflow-x-auto border-x' >
120
120
< Table >
121
121
< TableBody >
122
122
{ ! isError && table . getRowModel ( ) . rows ?. length ? (
@@ -139,9 +139,9 @@ export function QuestionAttemptsTable<TValue>({
139
139
</ TableBody >
140
140
</ Table >
141
141
</ ScrollArea >
142
- < div className = 'sticky bottom-0 rounded-b-md border' >
142
+ < div className = 'border-border sticky bottom-0 rounded-b-md border' >
143
143
< Table >
144
- < TableFooter >
144
+ < TableFooter className = 'border-t-border' >
145
145
< TableRow >
146
146
< TableCell colSpan = { columns . length } >
147
147
< Pagination className = 'flex items-center justify-end space-x-2 p-2' >
Original file line number Diff line number Diff line change @@ -54,10 +54,14 @@ export const ComboboxMulti = React.forwardRef<
54
54
< ChevronsUpDown className = 'ml-2 size-4 shrink-0 opacity-50' />
55
55
</ Button >
56
56
</ PopoverTrigger >
57
- < PopoverContent ref = { ref } className = { cn ( 'w-[200px] p-0' , className ) } { ...props } >
57
+ < PopoverContent
58
+ ref = { ref }
59
+ className = { cn ( 'w-[200px] p-0 border-secondary-foreground/40' , className ) }
60
+ { ...props }
61
+ >
58
62
< Command >
59
63
< CommandInput placeholder = { placeholderText } />
60
- < CommandList >
64
+ < CommandList className = '' >
61
65
< CommandEmpty > { noOptionsText } </ CommandEmpty >
62
66
< CommandGroup >
63
67
{ options . map ( ( option ) => (
Original file line number Diff line number Diff line change @@ -39,7 +39,10 @@ const CommandInput = React.forwardRef<
39
39
React . ElementRef < typeof CommandPrimitive . Input > ,
40
40
React . ComponentPropsWithoutRef < typeof CommandPrimitive . Input >
41
41
> ( ( { className, ...props } , ref ) => (
42
- < div className = 'flex items-center border-b px-3' cmdk-input-wrapper = '' >
42
+ < div
43
+ className = 'border-secondary-foreground/40 flex items-center border-b px-3'
44
+ cmdk-input-wrapper = ''
45
+ >
43
46
< MagnifyingGlassIcon className = 'mr-2 size-4 shrink-0 opacity-50' />
44
47
< CommandPrimitive . Input
45
48
ref = { ref }
You can’t perform that action at this time.
0 commit comments