1
- import React , { useState } from "react" ;
1
+ import React , { useState } from "react" ;
2
2
import AceEditor from "react-ace" ;
3
3
4
4
import "ace-builds/src-noconflict/mode-python" ;
@@ -7,6 +7,11 @@ import "ace-builds/src-noconflict/ext-language_tools";
7
7
import "ace-builds/src-noconflict/ext-searchbox" ;
8
8
import "ace-builds/src-noconflict/ext-inline_autocomplete" ;
9
9
import "ace-builds/src-noconflict/keybinding-vim" ;
10
+ import "ace-builds/src-min-noconflict/ext-searchbox" ;
11
+ import "ace-builds/src-min-noconflict/ext-language_tools" ;
12
+ import PeerprepDropdown from "@/components/shared/PeerprepDropdown" ;
13
+
14
+ import { Question } from "@/api/structs" ;
10
15
11
16
const languages = [
12
17
"javascript" ,
@@ -27,92 +32,73 @@ const themes = [
27
32
"textmate" ,
28
33
"solarized_dark" ,
29
34
"solarized_light" ,
30
- "terminal"
35
+ "terminal" ,
31
36
] ;
32
37
33
- languages . forEach ( lang => {
38
+ languages . forEach ( ( lang ) => {
34
39
require ( `ace-builds/src-noconflict/mode-${ lang } ` ) ;
35
40
require ( `ace-builds/src-noconflict/snippets/${ lang } ` ) ;
36
41
} ) ;
37
42
38
- themes . forEach ( theme => require ( `ace-builds/src-noconflict/theme-${ theme } ` ) ) ;
39
-
40
- import "ace-builds/src-min-noconflict/ext-searchbox" ;
41
- import "ace-builds/src-min-noconflict/ext-language_tools" ;
42
-
43
-
44
- import { Question } from "@/api/structs" ;
43
+ themes . forEach ( ( theme ) => require ( `ace-builds/src-noconflict/theme-${ theme } ` ) ) ;
45
44
46
45
interface Props {
47
46
question : Question ;
48
47
}
49
48
50
-
51
- export default function CollabEditor ( { question} : Props ) {
52
- const [ theme , setTheme ] = useState ( "twilight" )
53
- const [ fontSize , setFontSize ] = useState ( 16 )
54
- const [ language , setLanguage ] = useState ( "python" )
55
-
49
+ export default function CollabEditor ( { question } : Props ) {
50
+ const [ theme , setTheme ] = useState ( "twilight" ) ;
51
+ const [ fontSize , setFontSize ] = useState ( 16 ) ;
52
+ const [ language , setLanguage ] = useState ( "python" ) ;
56
53
57
54
const handleOnChange = ( newValue : string ) => {
58
55
console . log ( "Content changed:" , newValue ) ;
59
56
} ;
60
57
61
58
const handleOnLoad = ( editor : any ) => {
62
- editor . container . style . resize = "both"
63
- }
59
+ editor . container . style . resize = "both" ;
60
+ } ;
64
61
65
62
// TODO: to be taken from question props instead
66
63
// const value = question[language] ?? "// Comment"
67
64
const value = `def foo:
68
- pass`
69
-
70
-
71
- return < >
72
- < div className = "flex space-x-4 items-center p-4" >
73
- < div className = "flex flex-col" >
74
- < label className = "font-semibold mb-1" > Font Size</ label >
75
- < input
65
+ pass` ;
66
+
67
+ return (
68
+ < >
69
+ < div className = "flex space-x-4 items-center p-4" >
70
+ < div className = "flex flex-col" >
71
+ < label className = "font-semibold mb-1" > Font Size</ label >
72
+ < input
76
73
type = "number"
77
74
className = "border border-gray-600 bg-gray-800 text-white p-2 rounded w-20"
78
75
value = { fontSize }
79
76
onChange = { ( e ) => setFontSize ( Number ( e . target . value ) ) }
77
+ />
78
+ </ div >
79
+
80
+ < PeerprepDropdown
81
+ label = { "Theme" }
82
+ value = { theme }
83
+ onChange = { ( e ) => setTheme ( e . target . value ) }
84
+ options = { themes }
85
+ className = {
86
+ "border border-gray-600 bg-gray-800 text-white p-2 rounded"
87
+ }
80
88
/>
81
- </ div >
82
-
83
- < div className = "flex flex-col" >
84
- < label className = "font-semibold mb-1" > Theme</ label >
85
- < select
86
- className = "border border-gray-600 bg-gray-800 text-white p-2 rounded"
87
- value = { theme }
88
- onChange = { ( e ) => setTheme ( e . target . value ) }
89
- >
90
- { themes . map ( ( theme ) => (
91
- < option key = { theme } value = { theme } >
92
- { theme }
93
- </ option >
94
- ) ) }
95
- </ select >
96
- </ div >
97
89
98
- < div className = "flex flex-col" >
99
- < label className = "font-semibold mb-1" > Language</ label >
100
- < select
101
- className = "border border-gray-600 bg-gray-800 text-white p-2 rounded"
102
- value = { language }
103
- onChange = { ( e ) => setLanguage ( e . target . value ) }
104
- >
105
- { languages . map ( ( lang ) => (
106
- < option key = { lang } value = { lang } >
107
- { lang }
108
- </ option >
109
- ) ) }
110
- </ select >
90
+ < PeerprepDropdown
91
+ label = { "Language" }
92
+ value = { language }
93
+ onChange = { ( e ) => setLanguage ( e . target . value ) }
94
+ options = { languages }
95
+ className = {
96
+ "border border-gray-600 bg-gray-800 text-white p-2 rounded"
97
+ }
98
+ />
111
99
</ div >
112
- </ div >
113
-
114
100
115
- < AceEditor
101
+ < AceEditor
116
102
mode = { language }
117
103
className = { "editor" }
118
104
width = { "90%" }
@@ -133,7 +119,8 @@ export default function CollabEditor({question}: Props) {
133
119
enableSnippets : false ,
134
120
showLineNumbers : true ,
135
121
tabSize : 4 ,
136
- } } />
137
- </ >
138
-
139
- }
122
+ } }
123
+ />
124
+ </ >
125
+ ) ;
126
+ }
0 commit comments