*]:tw-backdrop-brightness-25 ' : '[&>*]:tw-backdrop-brightness-85'} ${darkMode ? '[&>*]:tw-bg-neutral-700/50' : '[&>*]:tw-bg-neutral-300/50'}
+
*]:tw-backdrop-brightness-25 ' : '[&>*]:tw-backdrop-brightness-85'}
tw-text-transparent tw-flex tw-flex-col tw-w-full tw-h-full tw-place-self-center tw-place-content-center tw-place-items-center`}>
diff --git a/apps/web/src/redux/slices/dashboardSlice.ts b/apps/web/src/redux/slices/dashboardSlice.ts
index 93065d0..66809d4 100644
--- a/apps/web/src/redux/slices/dashboardSlice.ts
+++ b/apps/web/src/redux/slices/dashboardSlice.ts
@@ -2,6 +2,7 @@ import { createSlice } from '@reduxjs/toolkit'
// Define a type for the slice state
interface DashboardState {
+ languages: string[],
languageDefault: string,
categoryDefault: string,
categoryRouteDefault: string,
@@ -18,10 +19,12 @@ interface DashboardState {
// Define the initial state using that type
const initialState: DashboardState = {
+ languages: ['javascript'],
languageDefault: import.meta.env.VITE_DEFAULT_LANGUAGE,
categoryDefault: import.meta.env.VITE_DEFAULT_CATEGORY,
categoryRouteDefault: import.meta.env.VITE_DEFAULT_ROUTE,
category: import.meta.env.VITE_DEFAULT_CATEGORY,
+ language: import.meta.env.VITE_DEFAULT_LANGUAGE,
categoryInfo: {},
categoryRoute: import.meta.env.VITE_DEFAULT_ROUTE,
question: {},
@@ -42,7 +45,7 @@ const initialState: DashboardState = {
_EMAIL_CONFIRMED: false,
_EMAIL_PASSCODE: '',
_PASSWORD: '',
- _DEFAULT_LANGUAGE: '',
+ _DEFAULT_LANGUAGE: 'javascript',
_DEFAULT_ROUTE: '',
_POINTS_TOTAL: 0,
_POINTS_JAVASCRIPT: 0,
@@ -58,6 +61,7 @@ export const dashboardSlice = createSlice({
// `createSlice` will infer the state type from the `initialState` argument
reducers: {
menu: (state) => {
+ state.languages;
state.language;
state.languageDefault;
state.category;
@@ -70,6 +74,9 @@ export const dashboardSlice = createSlice({
state.consoleMessage;
state.user;
},
+ menuLanguages: (state, action) => {
+ state.languages = action.payload;
+ },
menuLanguage: (state, action) => {
state.language = action.payload;
},
@@ -98,7 +105,7 @@ export const dashboardSlice = createSlice({
},
});
-export const { menu, menuUser, menuLanguage, menuCategory, menuCategoryInfo, menuCategoryRoute, menuQuestion, menuPoints, menuConsoleMessage } = dashboardSlice.actions
+export const { menu, menuUser, menuLanguages, menuLanguage, menuCategory, menuCategoryInfo, menuCategoryRoute, menuQuestion, menuPoints, menuConsoleMessage } = dashboardSlice.actions
export default dashboardSlice.reducer;
diff --git a/apps/web/src/redux/store.ts b/apps/web/src/redux/store.ts
index df162b0..6c1efa5 100644
--- a/apps/web/src/redux/store.ts
+++ b/apps/web/src/redux/store.ts
@@ -1,12 +1,13 @@
-import { configureStore } from '@reduxjs/toolkit';
+import { configureStore} from '@reduxjs/toolkit';
//import { createStore, applyMiddleware, combineReducers } from 'redux';
// import monitorReducersEnhancer from './enhancers/monitorReducers'
-// import thunkMiddleware from 'redux-thunk'
+//import thunkMiddleware from 'redux-thunk'
import { dashboardSlice } from './slices/dashboardSlice.ts'
const store = configureStore({
reducer: {
- dashboard: dashboardSlice.reducer
+ dashboard: dashboardSlice.reducer,
+ devTools: process.env.NODE_ENV !== 'production',
},
})
diff --git a/apps/web/src/utils/constants.ts b/apps/web/src/utils/constants.ts
index 05038d7..70fdbfe 100644
--- a/apps/web/src/utils/constants.ts
+++ b/apps/web/src/utils/constants.ts
@@ -1,3 +1,8 @@
+/** Icons */
+import JS_Icon from "../assets/tech/javascript/javascript-original.svg";
+import JAVA_Icon from "../assets/tech/java/java-original.svg";
+import PY_Icon from "../assets/tech/python/python-original.svg";
+
export const DEFAULT_USER = {
_ID: '',
_CREATED_AT: new Date().toISOString(),
@@ -20,4 +25,10 @@ export const DEFAULT_USER = {
_POINTS_JAVA: 0 ,
_POINTS_PYTHON: 0,
_COURSES: '',
-}
\ No newline at end of file
+}
+
+export const _LANGUAGES_ALL = {
+ javascript: JS_Icon,
+ java: JAVA_Icon,
+ python: PY_Icon,
+}
From cd34e49268e5ae6424c8e05ec8e9ed7de833ae24 Mon Sep 17 00:00:00 2001
From: jazicorn <40859840+jazicorn@users.noreply.github.com>
Date: Sat, 30 Sep 2023 06:56:26 -0400
Subject: [PATCH 11/12] fixed endpoints
---
apps/api/src/classes/question.ts | 61 +++++++---
.../data/java/comments.controller.ts | 85 +++++++++++++
.../comments.controller.ts | 66 ++---------
.../javascript/variables/var.controller.ts | 112 ++++++++----------
.../variables/var.declare.controller.ts | 26 ++--
.../variables/var.scope.controller.ts | 24 ++--
.../var.scope.reassign.controller.ts | 6 +-
.../data/python/comments.controller.ts | 80 +++++++++++++
apps/api/src/data/java/java.comments.ts | 27 +++--
apps/api/src/data/python/python.comments.ts | 2 +-
apps/api/src/index.ts | 16 ++-
11 files changed, 317 insertions(+), 188 deletions(-)
create mode 100644 apps/api/src/controllers/data/java/comments.controller.ts
rename apps/api/src/controllers/data/{comments => javascript}/comments.controller.ts (57%)
create mode 100644 apps/api/src/controllers/data/python/comments.controller.ts
diff --git a/apps/api/src/classes/question.ts b/apps/api/src/classes/question.ts
index ce52be2..8e1ca29 100644
--- a/apps/api/src/classes/question.ts
+++ b/apps/api/src/classes/question.ts
@@ -22,24 +22,49 @@ export class Question implements Q {
_QUESTION_REFS!: object;
constructor(data) {
- this._QUESTION_CREATED_AT = new Date();
- this._QUESTION_UPDATED_AT = new Date();
- this._QUESTION_ID = data._QUESTION_ID || '';
- this._QUESTION_LANGUAGE = data._QUESTION_LANGUAGE;
- this._QUESTION_LEVEL = data._QUESTION_LEVEL || 1;
- this._QUESTION_POINTS = data._QUESTION_POINTS || 1;
- this._QUESTION_TASK = data._QUESTION_TASK || '';
- this._QUESTION_DATA = data._QUESTION_DATA || {};
- this._QUESTION_RESULT = data._QUESTION_RESULT || {};
- this._QUESTION_HINTS = data._QUESTION_HINTS || {};
- this._QUESTION_BOILERPLATE = data._QUESTION_BOILERPLATE || '';
- this._QUESTION_CONDITIONS = data._QUESTION_CONDITIONS || {};
- this._QUESTION_CONSTRAINTS = data._QUESTION_CONSTRAINTS || {};
- this._QUESTION_CATEGORY = data._QUESTION_CATEGORY || '';
- this._QUESTION_CATEGORY_SUB = data._QUESTION_CATEGORY_SUB || '';
- this._QUESTION_TAGS = data._QUESTION_TAGS || [];
- this._QUESTION_REFS = data._QUESTION_REFS || {};
- this.set_QUESTION_ID(data._QUESTION_LANGUAGE);
+ const defaults = {
+ _QUESTION_CREATED_AT: new Date(),
+ _QUESTION_UPDATED_AT: new Date(),
+ _QUESTION_ID: `js-${nanoid(10)}`,
+ _QUESTION_LANGUAGE: "Javascript",
+ _QUESTION_LEVEL: 1,
+ _QUESTION_POINTS: 1,
+ _QUESTION_TASK: "",
+ _QUESTION_DATA: {},
+ _QUESTION_RESULT: {},
+ _QUESTION_HINTS: {},
+ _QUESTION_BOILERPLATE: "",
+ _QUESTION_CONDITIONS: {},
+ _QUESTION_CONSTRAINTS: {},
+ _QUESTION_CATEGORY: "",
+ _QUESTION_CATEGORY_SUB: "",
+ _QUESTION_TAGS: [],
+ _QUESTION_REFS: {},
+ }
+ let opts = Object.assign({}, defaults, data);
+ // assign options to instance data (using only property names contained
+ // in defaults object to avoid copying properties we don't want)
+ // Object.keys(defaults).forEach(prop => {
+ // this[prop] = opts[prop];
+ // });
+ this._QUESTION_CREATED_AT = opts._QUESTION_CREATED_AT;
+ this._QUESTION_UPDATED_AT = opts._QUESTION_UPDATED_AT;
+ this._QUESTION_ID = opts._QUESTION_ID;
+ this._QUESTION_LANGUAGE = opts._QUESTION_LANGUAGE;
+ this._QUESTION_LEVEL = opts._QUESTION_LEVEL;
+ this._QUESTION_POINTS = opts._QUESTION_POINTS;
+ this._QUESTION_TASK = opts._QUESTION_TASK;
+ this._QUESTION_DATA = opts._QUESTION_DATA;
+ this._QUESTION_RESULT = opts._QUESTION_RESULT;
+ this._QUESTION_HINTS = opts._QUESTION_HINTS;
+ this._QUESTION_BOILERPLATE = opts._QUESTION_BOILERPLATE;
+ this._QUESTION_CONDITIONS = opts._QUESTION_CONDITIONS;
+ this._QUESTION_CONSTRAINTS = opts._QUESTION_CONSTRAINTS;
+ this._QUESTION_CATEGORY = opts._QUESTION_CATEGORY;
+ this._QUESTION_CATEGORY_SUB = opts._QUESTION_CATEGORY_SUB;
+ this._QUESTION_TAGS = opts._QUESTION_TAGS;
+ this._QUESTION_REFS = opts._QUESTION_REFS;
+ this.set_QUESTION_ID(opts._QUESTION_LANGUAGE);
}
public set_QUESTION_ID(_QUESTION_LANGUAGE) {
diff --git a/apps/api/src/controllers/data/java/comments.controller.ts b/apps/api/src/controllers/data/java/comments.controller.ts
new file mode 100644
index 0000000..7bd5fc2
--- /dev/null
+++ b/apps/api/src/controllers/data/java/comments.controller.ts
@@ -0,0 +1,85 @@
+'use strict';
+import { Request, Response } from 'express';
+import Router from 'express-promise-router';
+import client from '../../../config/db';
+import { Question } from '../../../classes/question';
+import { Q_Type } from '../../../types/types.question';
+import { getRandomInt } from '../../../utils/index';
+import { objSingle, objMulti } from '../../../data/java/java.comments';
+
+export default class VarDeclare {
+ public pathCommentsRandom = '/java/comments/all';
+ public pathCommentsSingle = '/java/comments/single/all';
+ public pathCommentsMulti = '/java/comments/multi/all';
+ public router = Router();
+ constructor() {
+ this.initializeRoutes();
+ }
+
+ public initializeRoutes() {
+ this.router.get(this.pathCommentsRandom, this.commentsRandom);
+ this.router.get(this.pathCommentsSingle, this.commentsSingle);
+ this.router.get(this.pathCommentsMulti, this.commentsMulti);
+ }
+
+ public commentsRandom = async (req: Request, res: Response) => {
+ const dataSingle = objSingle();
+ const dataMulti = objMulti();
+
+ const questionSingle = new Question(dataSingle);
+ const questionMulti = new Question(dataMulti);
+ const random = getRandomInt(2);
+
+ const randomQuestion = [dataSingle, dataMulti][random];
+
+ switch(req.method) {
+ case('GET'):
+ try {
+ res.status(200).send({ data: randomQuestion });
+ } catch {
+ res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ };
+ };
+
+ public commentsSingle = async (req: Request, res: Response) => {
+ //console.log("hello")
+ const dataObj = objSingle();
+ //console.log(dataObj)
+ const question = new Question(dataObj);
+ //console.log(question);
+ switch(req.method) {
+ case('GET'):
+ try {
+ res.status(200).send({ data: question });
+
+ } catch {
+ res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ }
+ };
+
+ public commentsMulti = async (req: Request, res: Response) => {
+ const dataObj = objMulti();
+ const question = new Question(dataObj);
+ switch(req.method) {
+ case('GET'):
+ try {
+ return res.status(200).send({ data: question });
+
+ } catch {
+ return res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ return res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ }
+ };
+
+}
diff --git a/apps/api/src/controllers/data/comments/comments.controller.ts b/apps/api/src/controllers/data/javascript/comments.controller.ts
similarity index 57%
rename from apps/api/src/controllers/data/comments/comments.controller.ts
rename to apps/api/src/controllers/data/javascript/comments.controller.ts
index b4cd687..29a685a 100644
--- a/apps/api/src/controllers/data/comments/comments.controller.ts
+++ b/apps/api/src/controllers/data/javascript/comments.controller.ts
@@ -6,13 +6,11 @@ import { Question } from '../../../classes/question';
import { Q_Type } from '../../../types/types.question';
import { getRandomInt } from '../../../utils/index';
import { objSingle as objSingleJs, objMulti as objMultiJs } from '../../../data/javascript/javascript.comments';
-import { objSingle as objSingleJava, objMulti as objMultiJava } from '../../../data/java/java.comments';
-import { objSingle as objSinglePy, objMulti as objMultiPy } from '../../../data/python/python.comments';
export default class VarDeclare {
- public pathCommentsRandom = '/:id/comments/all';
- public pathCommentsSingle = '/:id/comments/single/all';
- public pathCommentsMulti = '/:id/comments/multi/all';
+ public pathCommentsRandom = '/javascript/comments/all';
+ public pathCommentsSingle = '/javascript/comments/single/all';
+ public pathCommentsMulti = '/javascript/comments/multi/all';
public router = Router();
constructor() {
this.initializeRoutes();
@@ -25,26 +23,8 @@ export default class VarDeclare {
}
public commentsRandom = async (req: Request, res: Response) => {
- let dataSingle
- let dataMulti
-
- switch(req.params.id.toLowerCase()) {
- case("javascript"):
- dataSingle = objSingleJs();
- dataMulti = objMultiJs();
- break
- case("java"):
- dataSingle = objSingleJava();
- dataMulti = objMultiJava();
- break
- case("python"):
- dataSingle = objSinglePy();
- dataMulti = objMultiPy();
- break
- default:
- dataSingle = objSingleJs();
- dataMulti = objMultiJs();
- }
+ const dataSingle = objSingleJs();
+ const dataMulti = objMultiJs();
const questionSingle = new Question(dataSingle);
const questionMulti = new Question(dataMulti);
@@ -54,7 +34,7 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
- try {
+ try {
res.status(200).send({ data: randomQuestion });
} catch {
res.status(500).send({ error: "Something went wrong" });
@@ -66,24 +46,11 @@ export default class VarDeclare {
};
public commentsSingle = async (req: Request, res: Response) => {
- let data;
- switch(req.params.id.toLowerCase()) {
- case("javascript"):
- data = objSingleJs();
- break
- case("java"):
- data = objSingleJava();
- break
- case("python"):
- data = objSinglePy();
- break
- default:
- data = objSingleJs();
- }
+ const data = objSingleJs();
const question = new Question(data);
switch(req.method) {
case('GET'):
- try {
+ try {
res.status(200).send({ data: question });
} catch {
res.status(500).send({ error: "Something went wrong" });
@@ -95,24 +62,11 @@ export default class VarDeclare {
};
public commentsMulti = async (req: Request, res: Response) => {
- let data;
- switch(req.params.id.toLowerCase()) {
- case("javascript"):
- data = objMultiJs();
- break
- case("java"):
- data = objMultiJava();
- break
- case("python"):
- data = objMultiPy();
- break
- default:
- data = objMultiJs();
- }
+ const data = objMultiJs();
const question = new Question(data);
switch(req.method) {
case('GET'):
- try {
+ try {
return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
diff --git a/apps/api/src/controllers/data/javascript/variables/var.controller.ts b/apps/api/src/controllers/data/javascript/variables/var.controller.ts
index fb12bac..9d3af0b 100644
--- a/apps/api/src/controllers/data/javascript/variables/var.controller.ts
+++ b/apps/api/src/controllers/data/javascript/variables/var.controller.ts
@@ -13,17 +13,17 @@ import cors from 'cors';
export default class VarGeneral {
/**Public: Get random var */
- public pathRandom = '/:id/var/all';
+ public pathRandom = '/javascript/var/all';
/**Public: Get All Var Category Questions*/
- public pathVar = '/:id/var';
+ public pathVar = '/javascript/var';
/**Public: Get Var Category Question by ID*/
- public pathVarId = '/:id/var/get/:id';
+ public pathVarId = '/javascript/var/get/:id';
/**Private: Create Var Question*/
- public pathVarNew = '/:id/var/new';
+ public pathVarNew = '/javascript/var/new';
/**Private: Update Var Question*/
- public pathVarUpdate = '/:id/var/update/:id';
+ public pathVarUpdate = '/javascript/var/update/:id';
/**Private: Delete Var Question';*/
- public pathVarDelete = '/:id/var/delete/:id';
+ public pathVarDelete = '/javascript/var/delete/:id';
/**Express Router */
public router = Router();
/**Cors Options*/
@@ -59,9 +59,7 @@ export default class VarGeneral {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: varRandom });
- }
+ return res.status(200).send({ data: varRandom });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -75,11 +73,9 @@ export default class VarGeneral {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- const id = req.params.id;
- const results = await sql`SELECT * FROM _QUESTIONS WHERE _QUESTIONS_CATEGORY = 'variables'`;
+ const results = await sql`SELECT * FROM _QUESTIONS WHERE _QUESTIONS_CATEGORY = 'variables'`;
- return res.status(200).send({ data: results });
+ return res.status(200).send({ data: results });
}
} catch {
return res.status(500).send({ error: "Something went wrong" });
@@ -94,8 +90,6 @@ export default class VarGeneral {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- const id = req.params.id;
const results = await sql`SELECT * FROM _QUESTIONS WHERE _QUESTION_ID = ${id}`;
return res.status(200).send({ data: results });
@@ -113,8 +107,6 @@ export default class VarGeneral {
switch(req.method) {
case('UPDATE'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- const id = req.params.id;
const results = await sql`SELECT * FROM _QUESTIONS WHERE _QUESTION_ID = ${id}`;
return res.status(200);
@@ -132,49 +124,47 @@ export default class VarGeneral {
switch(req.method) {
case('POST'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- const data: Q_Type = req.body;
- const question = new Question(data);
- const results = await sql`INSERT INTO _QUESTIONS (
- _QUESTION_CREATED_AT,
- _QUESTION_UPDATED_AT,
- _QUESTION_ID,
- _QUESTION_LANGUAGE,
- _QUESTION_LEVEL,
- _QUESTION_POINTS,
- _QUESTION_TASK,
- _QUESTION_DATA,
- _QUESTION_RESULT,
- _QUESTION_HINTS,
- _QUESTION_BOILERPLATE,
- _QUESTION_CONDITIONS,
- _QUESTION_CONSTRAINTS,
- _QUESTION_CATEGORY,
- _QUESTION_CATEGORY_SUB,
- _QUESTION_TAGS,
- _QUESTION_REFS,
- ) VALUES (
- ${question._QUESTION_CREATED_AT},
- ${question._QUESTION_UPDATED_AT},
- ${question._QUESTION_ID},
- ${question._QUESTION_LANGUAGE},
- ${question._QUESTION_LEVEL},
- ${question._QUESTION_POINTS},
- ${question._QUESTION_TASK},
- ${question._QUESTION_DATA},
- ${question._QUESTION_RESULT},
- ${question._QUESTION_HINTS},
- ${question._QUESTION_BOILERPLATE},
- ${question._QUESTION_CONDITIONS},
- ${question._QUESTION_CONSTRAINTS},
- ${question._QUESTION_CATEGORY},
- ${question._QUESTION_CATEGORY_SUB},
- ${question._QUESTION_TAGS},
- ${question._QUESTION_REFS}
- )`;
-
- return res.status(200);
- }
+ const data: Q_Type = req.body;
+ const question = new Question(data);
+ const results = await sql`INSERT INTO _QUESTIONS (
+ _QUESTION_CREATED_AT,
+ _QUESTION_UPDATED_AT,
+ _QUESTION_ID,
+ _QUESTION_LANGUAGE,
+ _QUESTION_LEVEL,
+ _QUESTION_POINTS,
+ _QUESTION_TASK,
+ _QUESTION_DATA,
+ _QUESTION_RESULT,
+ _QUESTION_HINTS,
+ _QUESTION_BOILERPLATE,
+ _QUESTION_CONDITIONS,
+ _QUESTION_CONSTRAINTS,
+ _QUESTION_CATEGORY,
+ _QUESTION_CATEGORY_SUB,
+ _QUESTION_TAGS,
+ _QUESTION_REFS,
+ ) VALUES (
+ ${question._QUESTION_CREATED_AT},
+ ${question._QUESTION_UPDATED_AT},
+ ${question._QUESTION_ID},
+ ${question._QUESTION_LANGUAGE},
+ ${question._QUESTION_LEVEL},
+ ${question._QUESTION_POINTS},
+ ${question._QUESTION_TASK},
+ ${question._QUESTION_DATA},
+ ${question._QUESTION_RESULT},
+ ${question._QUESTION_HINTS},
+ ${question._QUESTION_BOILERPLATE},
+ ${question._QUESTION_CONDITIONS},
+ ${question._QUESTION_CONSTRAINTS},
+ ${question._QUESTION_CATEGORY},
+ ${question._QUESTION_CATEGORY_SUB},
+ ${question._QUESTION_TAGS},
+ ${question._QUESTION_REFS}
+ )`;
+
+ return res.status(200);
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -188,8 +178,6 @@ export default class VarGeneral {
switch(req.method) {
case('DELETE'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- const id = req.params.id;
const results = await sql`DELETE * FROM _QUESTIONS WHERE _QUESTION_ID = ${id}`;
return res.status(200);
diff --git a/apps/api/src/controllers/data/javascript/variables/var.declare.controller.ts b/apps/api/src/controllers/data/javascript/variables/var.declare.controller.ts
index 10e59d0..f1635e8 100644
--- a/apps/api/src/controllers/data/javascript/variables/var.declare.controller.ts
+++ b/apps/api/src/controllers/data/javascript/variables/var.declare.controller.ts
@@ -8,10 +8,10 @@ import { getRandomInt } from '../../../../utils/index';
import { objRandom, objRandomVar, objRandomConst, objRandomLet } from '../../../../data/javascript/javascript.var.declare'
export default class VarDeclare {
- public pathVarRandomDeclare = '/:id/var/declare/all'
- public pathVarDeclareVar = '/:id/var/declare/var';
- public pathVarDeclareConst = '/:id/var/declare/const';
- public pathVarDeclareLet = '/:id/var/declare/let';
+ public pathVarRandomDeclare = '/javascript/var/declare/all'
+ public pathVarDeclareVar = '/javascript/var/declare/var';
+ public pathVarDeclareConst = '/javascript/var/declare/const';
+ public pathVarDeclareLet = '/javascript/var/declare/let';
public router = Router();
constructor() {
this.initializeRoutes();
@@ -30,9 +30,7 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -48,9 +46,7 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -65,10 +61,8 @@ export default class VarDeclare {
const question: Q_Type = new Question(data);
switch(req.method) {
case('GET'):
- try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ try {
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -84,9 +78,7 @@ export default class VarDeclare {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
diff --git a/apps/api/src/controllers/data/javascript/variables/var.scope.controller.ts b/apps/api/src/controllers/data/javascript/variables/var.scope.controller.ts
index 5ca57fa..16ca0b7 100644
--- a/apps/api/src/controllers/data/javascript/variables/var.scope.controller.ts
+++ b/apps/api/src/controllers/data/javascript/variables/var.scope.controller.ts
@@ -8,10 +8,10 @@ import { getRandomInt } from '../../../../utils/index';
import { objBlockScope, objFuncScope, objGlobalScope } from '../../../../data/javascript/javascript.var.scope';
export default class VarScope {
- public pathVarRandomScope = '/:id/var/scope/all';
- public pathVarScopeBlock = '/:id/var/scope/block';
- public pathVarScopeFunc = '/:id/var/scope/func';
- public pathVarScopeGlobal = '/:id/var/scope/global';
+ public pathVarRandomScope = '/javascript/var/scope/all';
+ public pathVarScopeBlock = '/javascript/var/scope/block';
+ public pathVarScopeFunc = '/javascript/var/scope/func';
+ public pathVarScopeGlobal = '/javascript/var/scope/global';
public router = Router();
constructor() {
this.initializeRoutes();
@@ -31,9 +31,7 @@ export default class VarScope {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -49,9 +47,7 @@ export default class VarScope {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -67,9 +63,7 @@ export default class VarScope {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
@@ -85,9 +79,7 @@ export default class VarScope {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
diff --git a/apps/api/src/controllers/data/javascript/variables/var.scope.reassign.controller.ts b/apps/api/src/controllers/data/javascript/variables/var.scope.reassign.controller.ts
index 561a7fb..19ab19f 100644
--- a/apps/api/src/controllers/data/javascript/variables/var.scope.reassign.controller.ts
+++ b/apps/api/src/controllers/data/javascript/variables/var.scope.reassign.controller.ts
@@ -8,7 +8,7 @@ import { getRandomInt } from '../../../../utils/index';
import { objBlockScopeReassign } from '../../../../data/javascript/javascript.var.scope.reassign';
export default class VarScopeReassign {
- public pathVarReassignBlock = '/:id/var/scope/reassign/block';
+ public pathVarReassignBlock = '/javascript/var/scope/reassign/block';
public router = Router();
constructor() {
this.initializeRoutes();
@@ -24,9 +24,7 @@ export default class VarScopeReassign {
switch(req.method) {
case('GET'):
try {
- if(req.params.id.toLowerCase() === 'javascript') {
- return res.status(200).send({ data: question });
- }
+ return res.status(200).send({ data: question });
} catch {
return res.status(500).send({ error: "Something went wrong" });
}
diff --git a/apps/api/src/controllers/data/python/comments.controller.ts b/apps/api/src/controllers/data/python/comments.controller.ts
new file mode 100644
index 0000000..312f5fa
--- /dev/null
+++ b/apps/api/src/controllers/data/python/comments.controller.ts
@@ -0,0 +1,80 @@
+'use strict';
+import { Request, Response } from 'express';
+import Router from 'express-promise-router';
+import client from '../../../config/db';
+import { Question } from '../../../classes/question';
+import { Q_Type } from '../../../types/types.question';
+import { getRandomInt } from '../../../utils/index';
+import { objSingle as objSinglePy, objMulti as objMultiPy } from '../../../data/python/python.comments';
+
+export default class VarDeclare {
+ public pathCommentsRandom = '/python/comments/all';
+ public pathCommentsSingle = '/python/comments/single/all';
+ public pathCommentsMulti = '/python/comments/multi/all';
+ public router = Router();
+ constructor() {
+ this.initializeRoutes();
+ }
+
+ public initializeRoutes() {
+ this.router.get(this.pathCommentsRandom, this.commentsRandom);
+ this.router.get(this.pathCommentsSingle, this.commentsSingle);
+ this.router.get(this.pathCommentsMulti, this.commentsMulti);
+ }
+
+ public commentsRandom = async (req: Request, res: Response) => {
+ const dataSingle = objSinglePy();
+ const dataMulti = objMultiPy();
+
+ const questionSingle = new Question(dataSingle);
+ const questionMulti = new Question(dataMulti);
+ const random = getRandomInt(2);
+
+ const randomQuestion = [dataSingle, dataMulti][random];
+
+ switch(req.method) {
+ case('GET'):
+ try {
+ res.status(200).send({ data: randomQuestion });
+ } catch {
+ res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ };
+ };
+
+ public commentsSingle = async (req: Request, res: Response) => {
+ const data = objSinglePy();
+ const question = new Question(data);
+ switch(req.method) {
+ case('GET'):
+ try {
+ res.status(200).send({ data: question });
+ } catch {
+ res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ }
+ };
+
+ public commentsMulti = async (req: Request, res: Response) => {
+ const data = objMultiPy();
+ const question = new Question(data);
+ switch(req.method) {
+ case('GET'):
+ try {
+ return res.status(200).send({ data: question });
+ } catch {
+ return res.status(500).send({ error: "Something went wrong" });
+ }
+ break
+ default:
+ return res.status(400).send({ error: `${req.method} Method Not Allowed` });
+ }
+ };
+
+}
diff --git a/apps/api/src/data/java/java.comments.ts b/apps/api/src/data/java/java.comments.ts
index a1035a8..9d87ae2 100644
--- a/apps/api/src/data/java/java.comments.ts
+++ b/apps/api/src/data/java/java.comments.ts
@@ -6,31 +6,42 @@ export const objSingle = (): Q_Type => {
const personName = faker.person.firstName();
const keyword = "SingleLine";
const data = {
- _QUESTION_LANGUAGE: "Javascript",
+ _QUESTION_LANGUAGE: "Java",
_QUESTION_ID: '',
_QUESTION_LEVEL: 1,
_QUESTION_POINTS: 1,
- _QUESTION_TASK: `Using ${keyword} comments, comment the statement: Greeting User abouve the console.log('Hello ${personName}') method `,
- _QUESTION_DATA: { keyword: keyword, value: personName, returnValue: `console.log('Hello ${personName})` },
+ _QUESTION_TASK:
+ `Using ${keyword} comments, comment the statement: 'Greeting User' abouve the 'System.out.println('Hello ' + user) method'.`,
+ _QUESTION_DATA: { keyword: keyword, value: personName,
+ returnValue: `System.out.println("Hello " + ${personName})` },
_QUESTION_RESULT: {
0: {
all:true
},
1 : {
- answer: `function greetingUser() {// Only change code bellow this line // Greeting User console.log(\'Hello ${personName}\');// Only change code abouve this line}greetingUser()`,
+ answer: `class Main {
+ public static void main(String[] args) {
+ String user = "${personName}";
+ // Only change code bellow this line
+ // Greeting User
+ System.out.println("Hello " + user);
+ // Only change code abouve this line
+ }
+ }`,
optional: false
}
},
_QUESTION_HINTS: {},
- _QUESTION_BOILERPLATE: `function greetingUser() {\n// Only change code bellow this line \n\n Greeting User\nconsole.log(\'Hello ${personName}\');\n\n// Only change code abouve this line\n}\n\ngreetingUser()\n`,
+ _QUESTION_BOILERPLATE:
+ `class Main {\n\tpublic static void main(String[] args) {\n\t\t// Only change code bellow this line\n\t\tString user = "${personName}";\n\n\t\tGreeting User\n\t\tSystem.out.println("Hello " + user);\n\t\t\n\t\t// Only change code abouve this line\n\t}\n}`,
_QUESTION_CONDITIONS: {},
_QUESTION_CONSTRAINTS: {},
_QUESTION_CATEGORY: 'Comments',
_QUESTION_CATEGORY_SUB: '',
_QUESTION_TAGS: [],
_QUESTION_REFS: {
- "javascript.info/comments": "https://javascript.info/comments",
- "javascript.info/structure": "https://javascript.info/structure"
+ "java comments": "https://www.w3schools.com/java/java_comments.asp",
+ "java syntax": "https://www.w3schools.com/java/java_syntax.asp"
}
}
return data;
@@ -40,7 +51,7 @@ export const objMulti = (): Q_Type => {
const personName = faker.person.firstName();
const keyword = "MultiLine";
const data = {
- _QUESTION_LANGUAGE: "Javascript",
+ _QUESTION_LANGUAGE: "Java",
_QUESTION_ID: '',
_QUESTION_LEVEL: 1,
_QUESTION_POINTS: 1,
diff --git a/apps/api/src/data/python/python.comments.ts b/apps/api/src/data/python/python.comments.ts
index 5c20559..88d64e9 100644
--- a/apps/api/src/data/python/python.comments.ts
+++ b/apps/api/src/data/python/python.comments.ts
@@ -40,7 +40,7 @@ export const objMulti = (): Q_Type => {
const personName = faker.person.firstName();
const keyword = "MultiLine";
const data = {
- _QUESTION_LANGUAGE: "Javascript",
+ _QUESTION_LANGUAGE: "Python",
_QUESTION_ID: '',
_QUESTION_LEVEL: 1,
_QUESTION_POINTS: 1,
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index b2e8e3f..88acc76 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -2,9 +2,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import App from './server';
import Index from './controllers/index.controller';
-import Guest_Routes from './controllers/auth/guest/guest.controller';
-import Comments from './controllers/data/comments/comments.controller';
-import VarGeneral from './controllers/data/javascript/variables/var.controller';
+import guestRoutes from './controllers/auth/guest/guest.controller';
+import jsComments from './controllers/data/javascript/comments.controller';
+import javaComments from './controllers/data/java/comments.controller';
+import pythonComments from './controllers/data/python/comments.controller';
+//import VarGeneral from './controllers/data/javascript/variables/var.controller';
import VarDeclare from './controllers/data/javascript/variables/var.declare.controller';
import VarScope from './controllers/data/javascript/variables/var.scope.controller';
import VarScopeReassign from './controllers/data/javascript/variables/var.scope.reassign.controller';
@@ -13,9 +15,11 @@ const app = new App(
[],
[
new Index(),
- new Guest_Routes(),
- new Comments(),
- new VarGeneral(),
+ new guestRoutes(),
+ new jsComments(),
+ new javaComments(),
+ new pythonComments(),
+ //new VarGeneral(),
new VarDeclare(),
new VarScope(),
new VarScopeReassign()
From b348f17ffcc1084febd24a41c4269de7c43469e5 Mon Sep 17 00:00:00 2001
From: jazicorn <40859840+jazicorn@users.noreply.github.com>
Date: Sat, 30 Sep 2023 07:26:31 -0400
Subject: [PATCH 12/12] fixed code editor to display different languages
---
apps/web/package.json | 7 +
.../dashboard/dashboard-code/D_Editor.tsx | 73 ++++----
.../dashboard/dashboard-code/D_Problem.tsx | 48 ++---
apps/web/src/layout/Layout.D_Code.tsx | 41 +++--
apps/web/src/utils/constants.ts | 16 ++
yarn.lock | 164 ++++++++++++++++++
6 files changed, 284 insertions(+), 65 deletions(-)
diff --git a/apps/web/package.json b/apps/web/package.json
index 16b0f4e..fc02bc6 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -43,7 +43,9 @@
},
"dependencies": {
"@codemirror/commands": "^6.2.4",
+ "@codemirror/lang-java": "^6.0.1",
"@codemirror/lang-javascript": "^6.1.9",
+ "@codemirror/lang-python": "^6.1.3",
"@codemirror/view": "^6.16.0",
"@dicebear/collection": "^7.0.1",
"@dicebear/core": "^7.0.1",
@@ -72,6 +74,11 @@
"@tiptap/extension-link": "^2.0.3",
"@tiptap/pm": "^2.0.3",
"@tiptap/react": "^2.0.3",
+ "@uiw/codemirror-theme-dracula": "^4.21.18",
+ "@uiw/codemirror-theme-github": "^4.21.18",
+ "@uiw/codemirror-theme-material": "^4.21.18",
+ "@uiw/codemirror-theme-quietlight": "^4.21.18",
+ "@uiw/codemirror-theme-xcode": "^4.21.18",
"@uiw/codemirror-themes": "^4.21.9",
"@uiw/react-codemirror": "^4.21.9",
"add": "^2.0.6",
diff --git a/apps/web/src/components/dashboard/dashboard-code/D_Editor.tsx b/apps/web/src/components/dashboard/dashboard-code/D_Editor.tsx
index d50e45b..276bd95 100644
--- a/apps/web/src/components/dashboard/dashboard-code/D_Editor.tsx
+++ b/apps/web/src/components/dashboard/dashboard-code/D_Editor.tsx
@@ -19,10 +19,17 @@ import { notifications } from '@mantine/notifications';
import { IconX, IconCheck } from '@tabler/icons-react';
/** Codemirror */
import CodeMirror from '@uiw/react-codemirror';
-import { javascript } from '@codemirror/lang-javascript';
-import lightTheme from '../../../styles/style.codemirror.light';
-import darkTheme from '../../../styles/style.codemirror.dark';
-const extensions = [ javascript({ jsx: true })];
+/**CodeMirror Languages */
+//import lightTheme from '../../../styles/style.codemirror.light';
+//import darkTheme from '../../../styles/style.codemirror.dark';
+//const extensions = [ javascript({ jsx: true })];
+import { _LANGUAGES_CODE_MIRROR, _LANGUAGES_RAPID_API } from '../../../utils/constants';
+//import { dracula } from '@uiw/codemirror-theme-dracula';
+import { materialDark } from '@uiw/codemirror-theme-material';
+import { githubLight } from '@uiw/codemirror-theme-github'
+//import { quietlight } from '@uiw/codemirror-theme-quietlight';
+//import { xcodeLight, xcodeLightInit, xcodeDark, xcodeDarkInit } from '@uiw/codemirror-theme-xcode';
+
/** API url | Custom env mandatory to begin with VITE
* https://vitejs.dev/guide/env-and-mode.html#env-files */
@@ -42,31 +49,38 @@ const D_Editor = () => {
const getMenuRoute = useAppSelector((state:RootState) => state?.dashboard?.categoryRoute);
const getMenuLanguage = useAppSelector((state:RootState) => state?.dashboard?.language);
+ /**Get question url */
+ let url;
+ if(import.meta.env.PROD) {
+ url = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`
+ } else {
+ url = `/api/${getMenuLanguage}/${getMenuRoute}`
+ }
+
/** Retrieve Category Based Question */
- const getQuestion = useCallback( async () => {
+ const getQuestion = useCallback(async (url) => {
/** Retrieve Question from API */
- try {
- let res;
- const prodURL = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`;
- const devURL = `/api/${getMenuLanguage}/${getMenuRoute}`;
- if(import.meta.env.PROD) {
- res = await fetch(prodURL);
- const resJSON = res.json();
- return resJSON;
- } else {
- res = await fetch(devURL);
- const resJSON = res.json();
- return resJSON;
- }
+ try {
+ const result = await fetch(url, {
+ method: 'GET',
+ headers: {
+ 'Accept' : 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ }
+ );
+ const resJSON = await result.json();
+ //console.log("resjson", resJSON)
+ return resJSON;
} catch(error) {
console.log(error);
}
- }, [getMenuLanguage, getMenuRoute]);
+ },[]);
/** Generate Question */
const { isSuccess, data } = useQuery({
- queryKey: ['questionData'],
- queryFn: getQuestion,
+ queryKey: ['questionData', url],
+ queryFn: () => getQuestion(url),
refetchOnWindowFocus: false,
staleTime: 100 * (60 * 1000),
cacheTime: 100 * (60 * 1000),
@@ -171,8 +185,6 @@ const D_Editor = () => {
notifications.show({
id: 'correct',
withCloseButton: true,
- onClose: () => console.log('unmounted'),
- onOpen: () => console.log('mounted'),
autoClose: 2000,
title: "Answer Correct",
message: '',
@@ -204,7 +216,8 @@ const D_Editor = () => {
const resultsStrip = getMenuQuestion._QUESTION_RESULT[1].answer.replace(/\s+/g, '');
try {
if( userCode === resultsStrip ) {
- consoleTest(93, editor, '');
+ const languageId = _LANGUAGES_RAPID_API[getMenuLanguage.toLowerCase()];
+ consoleTest(languageId, editor, '');
setPoints(getMenuPoints + getMenuQuestion._QUESTION_POINTS);
}
} catch (e) {
@@ -212,8 +225,6 @@ const D_Editor = () => {
notifications.show({
id: 'incorrect',
withCloseButton: true,
- onClose: () => console.log('unmounted'),
- onOpen: () => console.log('mounted'),
autoClose: 2000,
title: "Answer Incorrect",
message: '',
@@ -225,12 +236,16 @@ const D_Editor = () => {
loading: false,
});
}
- }, [editor, getMenuQuestion._QUESTION_RESULT, getMenuQuestion._QUESTION_POINTS, consoleTest, setPoints, getMenuPoints]);
+ }, [editor, getMenuQuestion._QUESTION_RESULT, getMenuQuestion._QUESTION_POINTS, getMenuLanguage, consoleTest, setPoints, getMenuPoints]);
useEffect(() => {
dispatch(menuConsoleMessage(consoleMessage));
},[consoleMessage, dispatch]);
+
+ const editorLanguage = _LANGUAGES_CODE_MIRROR[getMenuLanguage.toLowerCase()];
+ //console.log(editorLanguage);
+
/** Render if Successful */
if (isSuccess) return (
@@ -261,8 +276,8 @@ const D_Editor = () => {
value={editor}
height={isMobile ? "250px" : "300px"}
maxHeight="100%"
- theme={darkMode ? darkTheme : lightTheme}
- extensions={extensions}
+ theme={darkMode ? materialDark : githubLight }
+ extensions={editorLanguage}
onChange={onChange}
/>
diff --git a/apps/web/src/components/dashboard/dashboard-code/D_Problem.tsx b/apps/web/src/components/dashboard/dashboard-code/D_Problem.tsx
index 9870e7c..f2e37e5 100644
--- a/apps/web/src/components/dashboard/dashboard-code/D_Problem.tsx
+++ b/apps/web/src/components/dashboard/dashboard-code/D_Problem.tsx
@@ -27,31 +27,38 @@ const D_Problem = () => {
const getMenuRoute = useAppSelector((state:RootState) => state?.dashboard?.categoryRoute);
const getMenuLanguage = useAppSelector((state:RootState) => state?.dashboard?.language);
+ /**Get question url */
+ let url;
+ if(import.meta.env.PROD) {
+ url = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`
+ } else {
+ url = `/api/${getMenuLanguage}/${getMenuRoute}`
+ }
+
/** Retrieve Category Based Question */
- const getQuestion = useCallback( async () => {
+ const getQuestion = useCallback(async (url) => {
/** Retrieve Question from API */
try {
- let res;
- const prodURL = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`;
- const devURL = `/api/${getMenuLanguage}/${getMenuRoute}`;
- if(import.meta.env.PROD) {
- res = await fetch(prodURL);
- const resJSON = res.json();
- return resJSON;
- } else {
- res = await fetch(devURL);
- const resJSON = res.json();
- return resJSON;
- }
+ const result = await fetch(url, {
+ method: 'GET',
+ headers: {
+ 'Accept' : 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ }
+ );
+ const resJSON = await result.json();
+ //console.log("resJSON",resJSON);
+ return resJSON;
} catch(error) {
console.log(error);
}
- }, [getMenuLanguage, getMenuRoute]);
+ },[]);
/** Generate Question */
const { isSuccess, data, refetch } = useQuery({
- queryKey: ['questionData'],
- queryFn: getQuestion,
+ queryKey: ['questionData', url],
+ queryFn: () => getQuestion(url),
refetchOnWindowFocus: false,
staleTime: 100 * (60 * 1000),
cacheTime: 100 * (60 * 1000),
@@ -60,6 +67,7 @@ const D_Problem = () => {
/** Save Question to Redux Store */
useEffect(() => {
if(data !== undefined) {
+ //console.log(data.data)
dispatch(menuQuestion(data.data));
}
}, [dispatch, data]);
@@ -108,11 +116,11 @@ const D_Problem = () => {
const regex = /[""]/g;
const wordStrip = word.replace(regex, '');
if(word.match(regex)) {
- return
+ return (
- {wordStrip}
-
-
+ {wordStrip}
+
+ )
}
return
{word}
})}
diff --git a/apps/web/src/layout/Layout.D_Code.tsx b/apps/web/src/layout/Layout.D_Code.tsx
index 6514e30..6a2f78b 100644
--- a/apps/web/src/layout/Layout.D_Code.tsx
+++ b/apps/web/src/layout/Layout.D_Code.tsx
@@ -34,32 +34,40 @@ const Layout_D_Code = () => {
const getMenuRoute = useAppSelector((state:RootState) => state?.dashboard?.categoryRoute);
const getMenuLanguage = useAppSelector((state:RootState) => state?.dashboard?.language);
+ /**Get question url */
+ let url;
+ if(import.meta.env.PROD) {
+ url = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`
+ } else {
+ url = `/api/${getMenuLanguage}/${getMenuRoute}`
+ }
+
/** Retrieve Category Based Question */
- const getQuestion = useCallback( async () => {
+ const getQuestion = useCallback(async (url) => {
/** Retrieve Question from API */
try {
- let res;
- const prodURL = `${baseURL}/${getMenuLanguage}/${getMenuRoute}`;
- const devURL = `/api/${getMenuLanguage}/${getMenuRoute}`;
- if(import.meta.env.PROD) {
- res = await fetch(prodURL);
- const resJSON = res.json();
- return resJSON;
- } else {
- res = await fetch(devURL);
- const resJSON = res.json();
- return resJSON;
- }
+ const result = await fetch(url, {
+ method: 'GET',
+ headers: {
+ 'Accept' : 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ }
+ );
+ const resJSON = await result.json();
+ //console.log("resjson", resJSON)
+ return resJSON;
} catch(error) {
console.log(error);
}
- }, [getMenuLanguage, getMenuRoute]);
+ },[]);
/** Generate Question */
const { isLoading, isFetching, isError, error, isSuccess, data } = useQuery({
- queryKey: ['questionData'],
- queryFn: getQuestion,
+ queryKey: ['questionData', url],
+ queryFn: () => getQuestion(url),
refetchOnWindowFocus: false,
+ keepPreviousData: true,
staleTime: 100 * (60 * 1000),
cacheTime: 100 * (60 * 1000),
});
@@ -67,6 +75,7 @@ const Layout_D_Code = () => {
/** Save Question to Redux Store */
useEffect(() => {
if(data !== undefined) {
+ //console.log(data.data)
dispatch(menuQuestion(data.data));
}
}, [dispatch, data]);
diff --git a/apps/web/src/utils/constants.ts b/apps/web/src/utils/constants.ts
index 70fdbfe..38fa17c 100644
--- a/apps/web/src/utils/constants.ts
+++ b/apps/web/src/utils/constants.ts
@@ -2,6 +2,10 @@
import JS_Icon from "../assets/tech/javascript/javascript-original.svg";
import JAVA_Icon from "../assets/tech/java/java-original.svg";
import PY_Icon from "../assets/tech/python/python-original.svg";
+/**CodeMirror Languages */
+import { javascript } from '@codemirror/lang-javascript';
+import { java } from '@codemirror/lang-java';
+import { python } from '@codemirror/lang-python';
export const DEFAULT_USER = {
_ID: '',
@@ -32,3 +36,15 @@ export const _LANGUAGES_ALL = {
java: JAVA_Icon,
python: PY_Icon,
}
+
+export const _LANGUAGES_CODE_MIRROR = {
+ javascript: [ javascript({ jsx: true })],
+ java: [java()],
+ python: [python()],
+}
+
+export const _LANGUAGES_RAPID_API = {
+ javascript: 93,
+ java: 91,
+ python: 92
+}
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 919b723..5905a64 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2019,6 +2019,23 @@ __metadata:
languageName: node
linkType: hard
+"@codemirror/autocomplete@npm:^6.3.2":
+ version: 6.9.1
+ resolution: "@codemirror/autocomplete@npm:6.9.1"
+ dependencies:
+ "@codemirror/language": ^6.0.0
+ "@codemirror/state": ^6.0.0
+ "@codemirror/view": ^6.17.0
+ "@lezer/common": ^1.0.0
+ peerDependencies:
+ "@codemirror/language": ^6.0.0
+ "@codemirror/state": ^6.0.0
+ "@codemirror/view": ^6.0.0
+ "@lezer/common": ^1.0.0
+ checksum: 96dad7a12429bf61e6f1bf75da731bf0dcbfeb56c33400b60a0de22049226e0926a53a174e84701812a235f8f144595ce53f0928054481bdf9cdc2ed3b8be20f
+ languageName: node
+ linkType: hard
+
"@codemirror/commands@npm:^6.0.0, @codemirror/commands@npm:^6.1.0, @codemirror/commands@npm:^6.2.4":
version: 6.2.4
resolution: "@codemirror/commands@npm:6.2.4"
@@ -2031,6 +2048,16 @@ __metadata:
languageName: node
linkType: hard
+"@codemirror/lang-java@npm:^6.0.1":
+ version: 6.0.1
+ resolution: "@codemirror/lang-java@npm:6.0.1"
+ dependencies:
+ "@codemirror/language": ^6.0.0
+ "@lezer/java": ^1.0.0
+ checksum: 4679104683cbffcd224ac04c7e5d144b787494697b26470b07017259035b7bb3fa62609d9a61bfbc566f1756d9f972f9f26d96a3c1362dd48881c1172f9a914d
+ languageName: node
+ linkType: hard
+
"@codemirror/lang-javascript@npm:^6.1.9":
version: 6.1.9
resolution: "@codemirror/lang-javascript@npm:6.1.9"
@@ -2046,6 +2073,17 @@ __metadata:
languageName: node
linkType: hard
+"@codemirror/lang-python@npm:^6.1.3":
+ version: 6.1.3
+ resolution: "@codemirror/lang-python@npm:6.1.3"
+ dependencies:
+ "@codemirror/autocomplete": ^6.3.2
+ "@codemirror/language": ^6.8.0
+ "@lezer/python": ^1.1.4
+ checksum: 65a0276a4503e4e3b70dd28d1c93ef472632b6d2c4bf3ae92d305d14ee8cf60b0bbbf62d5ceb51294de9598d9e2d42eafcde26f317ee7b90d0a11dfa863c1d1a
+ languageName: node
+ linkType: hard
+
"@codemirror/language@npm:^6.0.0, @codemirror/language@npm:^6.6.0":
version: 6.8.0
resolution: "@codemirror/language@npm:6.8.0"
@@ -2060,6 +2098,20 @@ __metadata:
languageName: node
linkType: hard
+"@codemirror/language@npm:^6.8.0":
+ version: 6.9.1
+ resolution: "@codemirror/language@npm:6.9.1"
+ dependencies:
+ "@codemirror/state": ^6.0.0
+ "@codemirror/view": ^6.0.0
+ "@lezer/common": ^1.1.0
+ "@lezer/highlight": ^1.0.0
+ "@lezer/lr": ^1.0.0
+ style-mod: ^4.0.0
+ checksum: 62265f1042d2edfd3a091c408d9d0071f23889099b2f6ce8275fa910118bd2c45b8c4b29228c7be6e6d5f0e0812a522de902bc75ba8d8b2e62e42ade1692a49a
+ languageName: node
+ linkType: hard
+
"@codemirror/lint@npm:^6.0.0":
version: 6.4.0
resolution: "@codemirror/lint@npm:6.4.0"
@@ -2112,6 +2164,17 @@ __metadata:
languageName: node
linkType: hard
+"@codemirror/view@npm:^6.17.0":
+ version: 6.20.2
+ resolution: "@codemirror/view@npm:6.20.2"
+ dependencies:
+ "@codemirror/state": ^6.1.4
+ style-mod: ^4.1.0
+ w3c-keyname: ^2.2.4
+ checksum: eaf47726bb94b40f12c6f1d3494b558addaa7cd98a4ff05bfea7439c03cca3967d73380346ea8b06021478c21ec336a74665c9acb44e2b0280d5e0da4714387b
+ languageName: node
+ linkType: hard
+
"@colors/colors@npm:1.5.0":
version: 1.5.0
resolution: "@colors/colors@npm:1.5.0"
@@ -3311,6 +3374,13 @@ __metadata:
languageName: node
linkType: hard
+"@lezer/common@npm:^1.1.0":
+ version: 1.1.0
+ resolution: "@lezer/common@npm:1.1.0"
+ checksum: 93c208a44d1c0bdf7407853ba7c4ddcedf1c52d1b82170813d83b9bd6301aa23587405ac54332fe39ce8bc37f706936ab237ceb4d3d535d1dead650153b6474c
+ languageName: node
+ linkType: hard
+
"@lezer/highlight@npm:^1.0.0, @lezer/highlight@npm:^1.1.3, @lezer/highlight@npm:^1.1.6":
version: 1.1.6
resolution: "@lezer/highlight@npm:1.1.6"
@@ -3320,6 +3390,16 @@ __metadata:
languageName: node
linkType: hard
+"@lezer/java@npm:^1.0.0":
+ version: 1.0.4
+ resolution: "@lezer/java@npm:1.0.4"
+ dependencies:
+ "@lezer/highlight": ^1.0.0
+ "@lezer/lr": ^1.0.0
+ checksum: 97f5a2c2d733afba5dc57a0da9a97515b19b5e63bb5937717dac4e8c9baed74d15c0cb5c1580858b678931f11d517c56d89f903968fa48931f9c62e2ea67a107
+ languageName: node
+ linkType: hard
+
"@lezer/javascript@npm:^1.0.0":
version: 1.4.5
resolution: "@lezer/javascript@npm:1.4.5"
@@ -3339,6 +3419,16 @@ __metadata:
languageName: node
linkType: hard
+"@lezer/python@npm:^1.1.4":
+ version: 1.1.8
+ resolution: "@lezer/python@npm:1.1.8"
+ dependencies:
+ "@lezer/highlight": ^1.0.0
+ "@lezer/lr": ^1.0.0
+ checksum: e4a4e0b0fd871acff25111d4f767944b5015479776504b85c4431859c8a2859fdfa6362f204f3027cf9858c7ea907fd57244852a18b67da9eba3b2fe38d31b03
+ languageName: node
+ linkType: hard
+
"@linaria/core@npm:4.2.9":
version: 4.2.9
resolution: "@linaria/core@npm:4.2.9"
@@ -6090,6 +6180,66 @@ __metadata:
languageName: node
linkType: hard
+"@uiw/codemirror-theme-dracula@npm:^4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-theme-dracula@npm:4.21.18"
+ dependencies:
+ "@uiw/codemirror-themes": 4.21.18
+ checksum: 565893d01d5b7ca046cec9d628b6c1114480a832e9a8db874eec6a49905f79366257dc60862f72639e1cdcfd6b9215acfdceb280ec8ef0f4b7db240361c4091e
+ languageName: node
+ linkType: hard
+
+"@uiw/codemirror-theme-github@npm:^4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-theme-github@npm:4.21.18"
+ dependencies:
+ "@uiw/codemirror-themes": 4.21.18
+ checksum: 549e589dab1ecd1c322211eb6813ec3fb05a1cce930e5bb592913a3d068d6858fcb327c4a89c928a19f786a559beef5c2265678ecf7cd084338f5f231ef05b8a
+ languageName: node
+ linkType: hard
+
+"@uiw/codemirror-theme-material@npm:^4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-theme-material@npm:4.21.18"
+ dependencies:
+ "@uiw/codemirror-themes": 4.21.18
+ checksum: 8a0ded86b418036baf5ed87e2e0120be0760bd9691528d896a332967e04718b9cf782cd45e52c335831d80744f3192ebf691df592980a1d90b617c3c85753465
+ languageName: node
+ linkType: hard
+
+"@uiw/codemirror-theme-quietlight@npm:^4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-theme-quietlight@npm:4.21.18"
+ dependencies:
+ "@uiw/codemirror-themes": 4.21.18
+ checksum: 99ca2af837d14d7d0114de9e45288eb16aab9e4645111886e7482d55933155042afac119b77dafd5cd65403108ae5f862f3c94a54d6377f011f9598368ea4cec
+ languageName: node
+ linkType: hard
+
+"@uiw/codemirror-theme-xcode@npm:^4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-theme-xcode@npm:4.21.18"
+ dependencies:
+ "@uiw/codemirror-themes": 4.21.18
+ checksum: 44e78b153b5178d4c31f516ba4c4873d45018d6d2d4efb1193db7e62429ebda81aad8f1cafe4caa17bfc1e23c5c8a76919e04e4e661dce4224cc55966e05d371
+ languageName: node
+ linkType: hard
+
+"@uiw/codemirror-themes@npm:4.21.18":
+ version: 4.21.18
+ resolution: "@uiw/codemirror-themes@npm:4.21.18"
+ dependencies:
+ "@codemirror/language": ^6.0.0
+ "@codemirror/state": ^6.0.0
+ "@codemirror/view": ^6.0.0
+ peerDependencies:
+ "@codemirror/language": ">=6.0.0"
+ "@codemirror/state": ">=6.0.0"
+ "@codemirror/view": ">=6.0.0"
+ checksum: 70f3e1cb5acdc47eff0a50aa3c70fc636e4122fa52471431fd7150910bf1ad6cb10c0913ab77faca343a550d550e37fac8a576e69b9eda1b1b48f121547365ca
+ languageName: node
+ linkType: hard
+
"@uiw/codemirror-themes@npm:^4.21.9":
version: 4.21.9
resolution: "@uiw/codemirror-themes@npm:4.21.9"
@@ -16382,6 +16532,13 @@ __metadata:
languageName: node
linkType: hard
+"style-mod@npm:^4.1.0":
+ version: 4.1.0
+ resolution: "style-mod@npm:4.1.0"
+ checksum: 8402b14ca11113a3640d46b3cf7ba49f05452df7846bc5185a3535d9b6a64a3019e7fb636b59ccbb7816aeb0725b24723e77a85b05612a9360e419958e13b4e6
+ languageName: node
+ linkType: hard
+
"styled-components@npm:^6.0.3":
version: 6.0.3
resolution: "styled-components@npm:6.0.3"
@@ -17785,7 +17942,9 @@ __metadata:
resolution: "web@workspace:apps/web"
dependencies:
"@codemirror/commands": ^6.2.4
+ "@codemirror/lang-java": ^6.0.1
"@codemirror/lang-javascript": ^6.1.9
+ "@codemirror/lang-python": ^6.1.3
"@codemirror/view": ^6.16.0
"@dicebear/collection": ^7.0.1
"@dicebear/core": ^7.0.1
@@ -17831,6 +17990,11 @@ __metadata:
"@types/styled-components": ^5.1.26
"@typescript-eslint/eslint-plugin": ^5.59.0
"@typescript-eslint/parser": ^5.59.0
+ "@uiw/codemirror-theme-dracula": ^4.21.18
+ "@uiw/codemirror-theme-github": ^4.21.18
+ "@uiw/codemirror-theme-material": ^4.21.18
+ "@uiw/codemirror-theme-quietlight": ^4.21.18
+ "@uiw/codemirror-theme-xcode": ^4.21.18
"@uiw/codemirror-themes": ^4.21.9
"@uiw/react-codemirror": ^4.21.9
"@vitejs/plugin-react": ^4.0.0