Skip to content

Commit c65d96e

Browse files
committed
add change language option
1 parent 671f6a1 commit c65d96e

1 file changed

Lines changed: 67 additions & 13 deletions

File tree

src/pages/Learn/index.js

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ const Back = styled.p`
7676
}
7777
`;
7878

79-
const onChange = (newValue) => {
80-
console.log('change', newValue);
81-
};
82-
8379
// MODAL
8480
const customStyles = {
8581
content: {
@@ -121,6 +117,35 @@ const CloseWrapper = styled.div`
121117
justify-content: flex-end;
122118
`;
123119

120+
const ChooseLanguage = styled.div`
121+
display: flex;
122+
align-items: center;
123+
margin-bottom: 20px;
124+
125+
select {
126+
width: 120px;
127+
height: 30px;
128+
border-radius: 20px;
129+
background-color: #009d86;
130+
color: #ffffff;
131+
padding: 5px 10px;
132+
}
133+
134+
select:focus {
135+
outline: none;
136+
}
137+
138+
p {
139+
font-size: 80%;
140+
margin-right: 15px;
141+
}
142+
`;
143+
144+
const Padding = styled.div`
145+
padding: 0 20px;
146+
`;
147+
148+
// MODAL
124149
const ModalClose = styled.div`
125150
width: 20px;
126151
height: 20px;
@@ -136,7 +161,16 @@ const ModalClose = styled.div`
136161

137162
Modal.setAppElement('#root');
138163

164+
// funstion app
139165
const Learn = () => {
166+
const [language, setLanguage] = useState('javascript');
167+
168+
const handleLanguage = (event) => {
169+
// console.log(language);
170+
setLanguage(event.target.value);
171+
// console.log(event.target.value);
172+
};
173+
140174
const [result, setResult] = useState(`
141175
/** Your test output will go here **/
142176
`);
@@ -167,6 +201,17 @@ const Learn = () => {
167201
setColorAnswer('#F44336');
168202
};
169203

204+
const [code, setCode] = useState(`// setup
205+
let myArr = [];
206+
207+
// only change code below this line
208+
`);
209+
210+
const onCodeChange = (newValue) => {
211+
// console.log('change', newValue);
212+
setCode(newValue);
213+
};
214+
170215
return (
171216
<MainWrapper>
172217
<MenuBar />
@@ -177,7 +222,6 @@ const Learn = () => {
177222
<Back>(back to List Topics)</Back>
178223
</Link>
179224
</SubWrapper>
180-
181225
<SubTopic>Perkenalan</SubTopic>
182226
<Text>
183227
Array merupakan variabel dengan satu nama, tetapi mengandung banyak
@@ -222,22 +266,32 @@ const Learn = () => {
222266
</ConceptSection>
223267
<CodeSection>
224268
<TitleEditor>Online Editor</TitleEditor>
269+
<Padding>
270+
<Text>
271+
Silahkan kerjakan latihan konsep pada code editor di bawah ini.
272+
</Text>
273+
<ChooseLanguage>
274+
<p>Pilih bahasa: </p>
275+
<select value={language} onChange={handleLanguage}>
276+
<option value="javascript">Javascript</option>
277+
<option value="java">Java</option>
278+
<option value="python">Python</option>
279+
<option value="csharp">C#</option>
280+
</select>
281+
</ChooseLanguage>
282+
</Padding>
225283
<AceEditor
226-
mode="javascript"
284+
mode={language}
227285
theme="tomorrow"
228-
onChange={onChange}
286+
onChange={onCodeChange}
229287
name="UNIQUE_ID_OF_DIV"
230288
editorProps={{ $blockScrolling: true }}
231289
width="100%"
232-
height="400px"
290+
height="300px"
233291
fontSize={16}
234292
showGutter={true}
235293
highlightActiveLine={true}
236-
value={`// setup
237-
let myArr = [];
238-
239-
// only change code below this line
240-
`}
294+
value={code}
241295
setOptions={{
242296
enableBasicAutocompletion: true,
243297
enableLiveAutocompletion: true,

0 commit comments

Comments
 (0)