Manu Arora commited on
Commit
7ef61fd
·
1 Parent(s): 0feacad

⚙️ Improvement: Code Refactoring

Browse files
src/components/CodeEditorWindow.js CHANGED
@@ -1,9 +1,6 @@
1
- import React, { useEffect, useState } from "react";
2
- import ReactDOM from "react-dom";
3
 
4
  import Editor from "@monaco-editor/react";
5
- import monacoThemes from "monaco-themes/themes/themelist";
6
- import { defineTheme } from "../lib/defineTheme";
7
 
8
  const CodeEditorWindow = ({ onChange, language, code, theme }) => {
9
  const [value, setValue] = useState(code || "");
 
1
+ import React, { useState } from "react";
 
2
 
3
  import Editor from "@monaco-editor/react";
 
 
4
 
5
  const CodeEditorWindow = ({ onChange, language, code, theme }) => {
6
  const [value, setValue] = useState(code || "");
src/components/CustomInput.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from "react";
2
+ import { classnames } from "../utils/general";
3
+
4
+ const CustomInput = ({ customInput, setCustomInput }) => {
5
+ return (
6
+ <>
7
+ {" "}
8
+ <textarea
9
+ rows="5"
10
+ value={customInput}
11
+ onChange={(e) => setCustomInput(e.target.value)}
12
+ placeholder={`Custom input`}
13
+ className={classnames(
14
+ "focus:outline-none w-full border-2 border-black z-10 rounded-md shadow-[5px_5px_0px_0px_rgba(0,0,0)] px-4 py-2 hover:shadow transition duration-200 bg-white mt-2"
15
+ )}
16
+ ></textarea>
17
+ </>
18
+ );
19
+ };
20
+
21
+ export default CustomInput;
src/components/Landing.js CHANGED
@@ -1,18 +1,20 @@
1
  import React, { useEffect, useState } from "react";
2
- import Select from "react-select";
3
  import CodeEditorWindow from "./CodeEditorWindow";
4
  import axios from "axios";
5
  import { classnames } from "../utils/general";
6
  import { languageOptions } from "../constants/languageOptions";
7
- import { customStyles } from "../constants/customStyles";
8
 
9
  import { ToastContainer, toast } from "react-toastify";
10
  import "react-toastify/dist/ReactToastify.css";
11
 
12
- import monacoThemes from "monaco-themes/themes/themelist";
13
  import { defineTheme } from "../lib/defineTheme";
14
  import useKeyPress from "../hooks/useKeyPress";
15
  import Footer from "./Footer";
 
 
 
 
 
16
 
17
  const javascriptDefault = `/**
18
  * Problem: Binary Search: Search a sorted array for a target value.
@@ -186,39 +188,6 @@ const Landing = () => {
186
  });
187
  };
188
 
189
- const getOutput = () => {
190
- let statusId = outputDetails?.status?.id;
191
-
192
- if (statusId === 6) {
193
- // compilation error
194
- return (
195
- <pre className="px-2 py-1 font-normal text-xs text-red-500">
196
- {atob(outputDetails?.compile_output)}
197
- </pre>
198
- );
199
- } else if (statusId === 3) {
200
- return (
201
- <pre className="px-2 py-1 font-normal text-xs text-green-500">
202
- {atob(outputDetails.stdout) !== null
203
- ? `${atob(outputDetails.stdout)}`
204
- : null}
205
- </pre>
206
- );
207
- } else if (statusId === 5) {
208
- return (
209
- <pre className="px-2 py-1 font-normal text-xs text-red-500">
210
- {`Time Limit Exceeded`}
211
- </pre>
212
- );
213
- } else {
214
- return (
215
- <pre className="px-2 py-1 font-normal text-xs text-red-500">
216
- {atob(outputDetails?.stderr)}
217
- </pre>
218
- );
219
- }
220
- };
221
-
222
  return (
223
  <>
224
  <ToastContainer
@@ -235,29 +204,10 @@ const Landing = () => {
235
  <div className="h-4 w-full bg-gradient-to-r from-pink-500 via-red-500 to-yellow-500"></div>
236
  <div className="flex flex-row">
237
  <div className="px-4 py-2">
238
- <Select
239
- placeholder={`Filter By Category`}
240
- options={languageOptions}
241
- styles={customStyles}
242
- defaultValue={languageOptions[0]}
243
- onChange={(selectedOption) => onSelectChange(selectedOption)}
244
- />
245
  </div>
246
  <div className="px-4 py-2">
247
- <Select
248
- placeholder={`Select Theme`}
249
- // options={languageOptions}
250
- options={Object.entries(monacoThemes).map(
251
- ([themeId, themeName]) => ({
252
- label: themeName,
253
- value: themeId,
254
- key: themeId,
255
- })
256
- )}
257
- value={theme}
258
- styles={customStyles}
259
- onChange={handleThemeChange}
260
- />
261
  </div>
262
  </div>
263
  <div className="flex flex-row space-x-4 items-start px-4 py-4">
@@ -271,21 +221,12 @@ const Landing = () => {
271
  </div>
272
 
273
  <div className="right-container flex flex-shrink-0 w-[30%] flex-col">
274
- <h1 className="font-bold text-xl bg-clip-text text-transparent bg-gradient-to-r from-slate-900 to-slate-700 mb-2">
275
- Output
276
- </h1>
277
- <div className="w-full h-56 bg-[#1e293b] rounded-md text-white font-normal text-sm overflow-y-auto">
278
- {outputDetails ? <>{getOutput()}</> : null}
279
- </div>
280
  <div className="flex flex-col items-end">
281
- <textarea
282
- rows="5"
283
- onChange={(e) => setCustomInput(e.target.value)}
284
- placeholder={`Custom input`}
285
- className={classnames(
286
- "focus:outline-none w-full border-2 border-black z-10 rounded-md shadow-[5px_5px_0px_0px_rgba(0,0,0)] px-4 py-2 hover:shadow transition duration-200 bg-white mt-2"
287
- )}
288
- ></textarea>
289
  <button
290
  onClick={handleCompile}
291
  disabled={!code}
@@ -297,28 +238,7 @@ const Landing = () => {
297
  {processing ? "Processing..." : "Compile and Execute"}
298
  </button>
299
  </div>
300
- {outputDetails && (
301
- <div className="metrics-container mt-4 flex flex-col space-y-3">
302
- <p className="text-sm">
303
- Status:{" "}
304
- <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
305
- {outputDetails?.status?.description}
306
- </span>
307
- </p>
308
- <p className="text-sm">
309
- Memory:{" "}
310
- <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
311
- {outputDetails?.memory}
312
- </span>
313
- </p>
314
- <p className="text-sm">
315
- Time:{" "}
316
- <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
317
- {outputDetails?.time}
318
- </span>
319
- </p>
320
- </div>
321
- )}
322
  </div>
323
  </div>
324
  <Footer />
 
1
  import React, { useEffect, useState } from "react";
 
2
  import CodeEditorWindow from "./CodeEditorWindow";
3
  import axios from "axios";
4
  import { classnames } from "../utils/general";
5
  import { languageOptions } from "../constants/languageOptions";
 
6
 
7
  import { ToastContainer, toast } from "react-toastify";
8
  import "react-toastify/dist/ReactToastify.css";
9
 
 
10
  import { defineTheme } from "../lib/defineTheme";
11
  import useKeyPress from "../hooks/useKeyPress";
12
  import Footer from "./Footer";
13
+ import OutputWindow from "./OutputWindow";
14
+ import CustomInput from "./CustomInput";
15
+ import OutputDetails from "./OutputDetails";
16
+ import ThemeDropdown from "./ThemeDropdown";
17
+ import LanguagesDropdown from "./LanguagesDropdown";
18
 
19
  const javascriptDefault = `/**
20
  * Problem: Binary Search: Search a sorted array for a target value.
 
188
  });
189
  };
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  return (
192
  <>
193
  <ToastContainer
 
204
  <div className="h-4 w-full bg-gradient-to-r from-pink-500 via-red-500 to-yellow-500"></div>
205
  <div className="flex flex-row">
206
  <div className="px-4 py-2">
207
+ <LanguagesDropdown onSelectChange={onSelectChange} />
 
 
 
 
 
 
208
  </div>
209
  <div className="px-4 py-2">
210
+ <ThemeDropdown handleThemeChange={handleThemeChange} theme={theme} />
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  </div>
212
  </div>
213
  <div className="flex flex-row space-x-4 items-start px-4 py-4">
 
221
  </div>
222
 
223
  <div className="right-container flex flex-shrink-0 w-[30%] flex-col">
224
+ <OutputWindow outputDetails={outputDetails} />
 
 
 
 
 
225
  <div className="flex flex-col items-end">
226
+ <CustomInput
227
+ customInput={customInput}
228
+ setCustomInput={setCustomInput}
229
+ />
 
 
 
 
230
  <button
231
  onClick={handleCompile}
232
  disabled={!code}
 
238
  {processing ? "Processing..." : "Compile and Execute"}
239
  </button>
240
  </div>
241
+ {outputDetails && <OutputDetails outputDetails={outputDetails} />}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  </div>
243
  </div>
244
  <Footer />
src/components/LanguagesDropdown.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from "react";
2
+ import Select from "react-select";
3
+ import { customStyles } from "../constants/customStyles";
4
+ import { languageOptions } from "../constants/languageOptions";
5
+
6
+ const LanguagesDropdown = ({ onSelectChange }) => {
7
+ return (
8
+ <Select
9
+ placeholder={`Filter By Category`}
10
+ options={languageOptions}
11
+ styles={customStyles}
12
+ defaultValue={languageOptions[0]}
13
+ onChange={(selectedOption) => onSelectChange(selectedOption)}
14
+ />
15
+ );
16
+ };
17
+
18
+ export default LanguagesDropdown;
src/components/OutputDetails.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from "react";
2
+
3
+ const OutputDetails = ({ outputDetails }) => {
4
+ return (
5
+ <div className="metrics-container mt-4 flex flex-col space-y-3">
6
+ <p className="text-sm">
7
+ Status:{" "}
8
+ <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
9
+ {outputDetails?.status?.description}
10
+ </span>
11
+ </p>
12
+ <p className="text-sm">
13
+ Memory:{" "}
14
+ <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
15
+ {outputDetails?.memory}
16
+ </span>
17
+ </p>
18
+ <p className="text-sm">
19
+ Time:{" "}
20
+ <span className="font-semibold px-2 py-1 rounded-md bg-gray-100">
21
+ {outputDetails?.time}
22
+ </span>
23
+ </p>
24
+ </div>
25
+ );
26
+ };
27
+
28
+ export default OutputDetails;
src/components/OutputWindow.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from "react";
2
+
3
+ const OutputWindow = ({ outputDetails }) => {
4
+ const getOutput = () => {
5
+ let statusId = outputDetails?.status?.id;
6
+
7
+ if (statusId === 6) {
8
+ // compilation error
9
+ return (
10
+ <pre className="px-2 py-1 font-normal text-xs text-red-500">
11
+ {atob(outputDetails?.compile_output)}
12
+ </pre>
13
+ );
14
+ } else if (statusId === 3) {
15
+ return (
16
+ <pre className="px-2 py-1 font-normal text-xs text-green-500">
17
+ {atob(outputDetails.stdout) !== null
18
+ ? `${atob(outputDetails.stdout)}`
19
+ : null}
20
+ </pre>
21
+ );
22
+ } else if (statusId === 5) {
23
+ return (
24
+ <pre className="px-2 py-1 font-normal text-xs text-red-500">
25
+ {`Time Limit Exceeded`}
26
+ </pre>
27
+ );
28
+ } else {
29
+ return (
30
+ <pre className="px-2 py-1 font-normal text-xs text-red-500">
31
+ {atob(outputDetails?.stderr)}
32
+ </pre>
33
+ );
34
+ }
35
+ };
36
+ return (
37
+ <>
38
+ <h1 className="font-bold text-xl bg-clip-text text-transparent bg-gradient-to-r from-slate-900 to-slate-700 mb-2">
39
+ Output
40
+ </h1>
41
+ <div className="w-full h-56 bg-[#1e293b] rounded-md text-white font-normal text-sm overflow-y-auto">
42
+ {outputDetails ? <>{getOutput()}</> : null}
43
+ </div>
44
+ </>
45
+ );
46
+ };
47
+
48
+ export default OutputWindow;
src/components/ThemeDropdown.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from "react";
2
+ import Select from "react-select";
3
+ import monacoThemes from "monaco-themes/themes/themelist";
4
+ import { customStyles } from "../constants/customStyles";
5
+
6
+ const ThemeDropdown = ({ handleThemeChange, theme }) => {
7
+ return (
8
+ <Select
9
+ placeholder={`Select Theme`}
10
+ // options={languageOptions}
11
+ options={Object.entries(monacoThemes).map(([themeId, themeName]) => ({
12
+ label: themeName,
13
+ value: themeId,
14
+ key: themeId,
15
+ }))}
16
+ value={theme}
17
+ styles={customStyles}
18
+ onChange={handleThemeChange}
19
+ />
20
+ );
21
+ };
22
+
23
+ export default ThemeDropdown;
src/constants/languageOptions.js CHANGED
@@ -1,57 +1,3 @@
1
- // export const languageOptions = [
2
- // {
3
- // label: "Javascript NodeJS",
4
- // value: "javascript",
5
- // apiLanguage: "JAVASCRIPT_NODE",
6
- // },
7
- // {
8
- // label: "C",
9
- // value: "c",
10
- // apiLanguage: "C",
11
- // },
12
- // {
13
- // label: "C++ 11",
14
- // value: "cpp",
15
- // apiLanguage: "CPP11",
16
- // },
17
- // {
18
- // label: "C++ 14",
19
- // value: "cpp",
20
- // apiLanguage: "CPP14",
21
- // },
22
- // {
23
- // label: "Java",
24
- // value: "java",
25
- // apiLanguage: "JAVA",
26
- // },
27
- // {
28
- // label: "Java 8",
29
- // value: "java",
30
- // apiLanguage: "JAVA8",
31
- // },
32
- // {
33
- // label: "C#",
34
- // value: "csharp",
35
- // apiLanguage: "CSHARP",
36
- // },
37
-
38
- // {
39
- // label: "Python 2",
40
- // value: "python",
41
- // apiLanguage: "PYTHON",
42
- // },
43
- // {
44
- // label: "Python 3",
45
- // value: "python",
46
- // apiLanguage: "PYTHON3",
47
- // },
48
- // {
49
- // label: "PHP",
50
- // value: "php",
51
- // apiLanguage: "PHP",
52
- // },
53
- // ];
54
-
55
  export const languageOptions = [
56
  {
57
  id: 63,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  export const languageOptions = [
2
  {
3
  id: 63,