From 89d1badb324608303daf5078339af3812ae5d15a Mon Sep 17 00:00:00 2001 From: Aayush Jain Date: Sat, 13 Mar 2021 18:05:38 +0530 Subject: [PATCH 1/8] Added Default Language Code --- .../components/SyntaxEditor/LanguageData.js | 112 +++++++++++++++--- .../components/SyntaxEditor/SyntaxEditor.js | 5 +- 2 files changed, 97 insertions(+), 20 deletions(-) diff --git a/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js b/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js index 2967cd3a8..5af92df1c 100644 --- a/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js +++ b/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js @@ -1,5 +1,4 @@ export const languages = [ - "c_cpp", "clojure", "csharp", @@ -18,8 +17,7 @@ export const languages = [ "sql", "swift", "typescript", - ]; - +]; export const defaultValue = `#include #define lli long long int @@ -42,14 +40,97 @@ int main() return 0; }`; +export const defaultLanguageCode = [ + { + id: 54, + code: '#include \nusing namespace std;\n\nint main() {\n\t\/\/ your code goes here\n\treturn 0;\n}\n', + }, + { + id: 50, + code: '#include \n\nint main(void) {\n\t\/\/ your code goes here\n\treturn 0;\n}\n', + }, + { + id: 86, + code: '; your code goes here\n', + }, + { + id: 62, + code: 'import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\/* Name of the class has to be \"Main\" only if the class is public. *\/\nclass Solution\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t\/\/ your code goes here\n\t}\n}\n', + }, + { + id: 51, + code: 'using System;\n\npublic class Test\n{\n\tpublic static void Main()\n\t{\n\t\t\/\/ your code goes here\n\t}\n}\n', + }, + { + id: 71, + code: '# your code goes here\n', + }, + { + id: 80, + code: '\n', + }, + { + id: 72, + code: '# your code goes here\n', + }, + { + id: 82, + code: '', + }, + { + id: 83, + code: '', + }, + { + id: 74, + code: '', + }, + { + id: 68, + code: '\n\t% your code goes here\n\ttrue.\n', + }, + { + id: 77, + code: '\t\t\tIDENTIFICATION DIVISION.\n\t\t\tPROGRAM-ID. hello.\n\t\t\tPROCEDURE DIVISION.\n\t\t\tDISPLAY \"Hello World!\".\n\t\t\tSTOP RUN.', + }, + { + id: 74, + code: '', + }, + { + id: 88, + code: '', + }, + { + id: 78, + code: '', + }, + { + id: 63, + code: '', + }, +]; + export const LangOptions = [ - "C" , - "C++" , + "C", + "C++", "Python", "JAVA", "JavaScript", "Kotlin", - "Clojure" , + "Clojure", "C#", "COBOL", "Erlang", @@ -61,11 +142,10 @@ export const LangOptions = [ "Ruby", "SQL", "Swift", - "TypeScript" -] + "TypeScript", +]; export const langId = { - "C" : 50, "C++" : 54, "Clojure" : 86, @@ -85,11 +165,9 @@ export const langId = { "SQL": 82, "Swift": 83, "TypeScript": 74 - - } - +}; + export const langMode = { - "C": "c_cpp", "C++": "c_cpp", "Clojure": "clojure", @@ -109,9 +187,7 @@ export const langMode = { "SQL": "sql", "Swift": "swift", "TypeScript": "typescript", - -} - +}; export const themes = [ "monokai", @@ -125,6 +201,4 @@ export const themes = [ "solarized_dark", "solarized_light", "terminal", - ]; - - \ No newline at end of file +]; diff --git a/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js b/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js index 612ac95c3..9ebf1835f 100644 --- a/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js +++ b/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js @@ -23,7 +23,7 @@ import Grid from "@material-ui/core/Grid"; import localClasses from "./SyntaxEditor.module.css"; import { languages, - defaultValue, + defaultLanguageCode, langMode, LangOptions, langId, @@ -73,6 +73,7 @@ const ICE = (props) => { ); }; const SyntaxEditor = (props) => { + const defaultValue = defaultLanguageCode[0].code; const [value, setValue] = useState(defaultValue); const [currLang, setCurrLang] = useState("C++"); const [theme, setTheme] = useState("monokai"); @@ -247,6 +248,8 @@ const SyntaxEditor = (props) => { value={currLang} onChange={(e) => { setCurrLang(e.target.value); + const newCode = defaultLanguageCode.filter(x => x.id == langId[e.target.value]); + setValue(newCode[0].code); }} label="Language" style={{ fontFamily: "poppins", color: "#ffffff" }} From d2f6fdcfa40ce1a740033f7af75b7400b7d2e304 Mon Sep 17 00:00:00 2001 From: Krishnaraj Yadav Date: Sun, 21 Mar 2021 12:24:41 +0530 Subject: [PATCH 2/8] #75 Fixed --- backend/server/index.js | 8 +++++--- backend/server/package-lock.json | 10 ++++++++++ backend/server/package.json | 2 ++ backend/server/rateLimiter.js | 10 ++++++++++ frontend/syntaxmeets/package-lock.json | 5 +++++ frontend/syntaxmeets/package.json | 1 + 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 backend/server/rateLimiter.js diff --git a/backend/server/index.js b/backend/server/index.js index 0ade59764..94b58902c 100644 --- a/backend/server/index.js +++ b/backend/server/index.js @@ -3,14 +3,16 @@ const server = require("http").createServer(app); const cors = require("cors"); const Rooms = require("./Utils/Rooms"); const io = require("socket.io")(server, { origins: "*:*" }); - +const helmet = require('helmet'); +const rateLimiter = require('./rateLimiter'); // instantiate a new rooms object to store all clients in the room const rooms = new Rooms(); +app.use(helmet()); // io.origins(["http://localhost:3000"]); app.use(cors()); -io.on("connection", (socket) => { +io.on("connection",rateLimiter , (socket) => { let roomId = 0; let userName = ""; let userId = 1; @@ -65,7 +67,7 @@ io.on("connection", (socket) => { }); }); -app.get("/", (req, res) => { +app.get("/",rateLimiter , (req, res) => { res.send({ response: "Server is up and Running." }).status(200); }); diff --git a/backend/server/package-lock.json b/backend/server/package-lock.json index 1bc630b45..37c874ebb 100644 --- a/backend/server/package-lock.json +++ b/backend/server/package-lock.json @@ -543,6 +543,11 @@ "vary": "~1.1.2" } }, + "express-rate-limit": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.6.tgz", + "integrity": "sha512-nE96xaxGfxiS5jP3tD3kIW1Jg9yQgX0rXCs3rCkZtmbWHEGyotwaezkLj7bnB41Z0uaOLM8W4AX6qHao4IZ2YA==" + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -651,6 +656,11 @@ "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==" }, + "helmet": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-4.4.1.tgz", + "integrity": "sha512-G8tp0wUMI7i8wkMk2xLcEvESg5PiCitFMYgGRc/PwULB0RVhTP5GFdxOwvJwp9XVha8CuS8mnhmE8I/8dx/pbw==" + }, "http-cache-semantics": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", diff --git a/backend/server/package.json b/backend/server/package.json index b35fa0caa..ee7eb0677 100644 --- a/backend/server/package.json +++ b/backend/server/package.json @@ -12,6 +12,8 @@ "dependencies": { "cors": "^2.8.5", "express": "^4.17.1", + "express-rate-limit": "^5.2.6", + "helmet": "^4.4.1", "nodemon": "^2.0.6", "socket.io": "^2.4.1" } diff --git a/backend/server/rateLimiter.js b/backend/server/rateLimiter.js new file mode 100644 index 000000000..5922d4705 --- /dev/null +++ b/backend/server/rateLimiter.js @@ -0,0 +1,10 @@ +const rateLimit = require('express-rate-limit'); + +const limit = rateLimit({ + windowMs: 1 * 60 * 1000, + max: 100, + message: + "Too many requests created from this IP, please try again after an hour" + }); + + module.exports = limit; \ No newline at end of file diff --git a/frontend/syntaxmeets/package-lock.json b/frontend/syntaxmeets/package-lock.json index bbfe2a488..75deaa83e 100644 --- a/frontend/syntaxmeets/package-lock.json +++ b/frontend/syntaxmeets/package-lock.json @@ -7938,6 +7938,11 @@ } } }, + "express-rate-limit": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.6.tgz", + "integrity": "sha512-nE96xaxGfxiS5jP3tD3kIW1Jg9yQgX0rXCs3rCkZtmbWHEGyotwaezkLj7bnB41Z0uaOLM8W4AX6qHao4IZ2YA==" + }, "ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", diff --git a/frontend/syntaxmeets/package.json b/frontend/syntaxmeets/package.json index 175dab190..3f5aec9ab 100644 --- a/frontend/syntaxmeets/package.json +++ b/frontend/syntaxmeets/package.json @@ -13,6 +13,7 @@ "axios": "^0.21.1", "bootstrap": "^4.5.3", "copy-to-clipboard": "^3.3.1", + "express-rate-limit": "^5.2.6", "fontsource-poppins": "^3.0.9", "react": "^16.13.1", "react-ace": "^9.1.4", From 7c37380be31daabbee39ca783bd1152d28718768 Mon Sep 17 00:00:00 2001 From: Krishnaraj Yadav Date: Mon, 22 Mar 2021 22:42:58 +0530 Subject: [PATCH 3/8] #75 - Resolving error --- backend/server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/server/index.js b/backend/server/index.js index 94b58902c..b3e06c804 100644 --- a/backend/server/index.js +++ b/backend/server/index.js @@ -12,7 +12,7 @@ app.use(helmet()); // io.origins(["http://localhost:3000"]); app.use(cors()); -io.on("connection",rateLimiter , (socket) => { +io.on("connection" , (socket) => { let roomId = 0; let userName = ""; let userId = 1; From 200be9aedc265acea45ddf83817868f06a55b5c6 Mon Sep 17 00:00:00 2001 From: Dhruv Kothari Date: Tue, 23 Mar 2021 18:34:44 +0530 Subject: [PATCH 4/8] dep no needed --- frontend/syntaxmeets/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/syntaxmeets/package.json b/frontend/syntaxmeets/package.json index 3f5aec9ab..175dab190 100644 --- a/frontend/syntaxmeets/package.json +++ b/frontend/syntaxmeets/package.json @@ -13,7 +13,6 @@ "axios": "^0.21.1", "bootstrap": "^4.5.3", "copy-to-clipboard": "^3.3.1", - "express-rate-limit": "^5.2.6", "fontsource-poppins": "^3.0.9", "react": "^16.13.1", "react-ace": "^9.1.4", From 6d34be85ae462ad306de6615217a3b7234b995ae Mon Sep 17 00:00:00 2001 From: Priyankcoder Date: Thu, 25 Mar 2021 17:43:18 +0530 Subject: [PATCH 5/8] add emoji picker --- frontend/syntaxmeets/package-lock.json | 14 +++-- frontend/syntaxmeets/package.json | 1 + .../src/components/SyntaxChat/SyntaxChat.js | 60 +++++++++++++++++-- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/frontend/syntaxmeets/package-lock.json b/frontend/syntaxmeets/package-lock.json index 75deaa83e..f4537b350 100644 --- a/frontend/syntaxmeets/package-lock.json +++ b/frontend/syntaxmeets/package-lock.json @@ -6703,6 +6703,15 @@ "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.7.2.tgz", "integrity": "sha512-A8OG5SR/ij3SsJdWDJdkkSYUjQdCUx6APQXem0SaEePBSRg4eymGYwBkKo1Y6DU+af/Jn2dBQqDBvjnr9Vi8nQ==" }, + "emoji-mart": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz", + "integrity": "sha512-sxpmMKxqLvcscu6mFn9ITHeZNkGzIvD0BSNFE/LJESPbCA8s1jM6bCDPjWbV31xHq7JXaxgpHxLB54RCbBZSlg==", + "requires": { + "@babel/runtime": "^7.0.0", + "prop-types": "^15.6.0" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -7938,11 +7947,6 @@ } } }, - "express-rate-limit": { - "version": "5.2.6", - "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.6.tgz", - "integrity": "sha512-nE96xaxGfxiS5jP3tD3kIW1Jg9yQgX0rXCs3rCkZtmbWHEGyotwaezkLj7bnB41Z0uaOLM8W4AX6qHao4IZ2YA==" - }, "ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", diff --git a/frontend/syntaxmeets/package.json b/frontend/syntaxmeets/package.json index 175dab190..71450beff 100644 --- a/frontend/syntaxmeets/package.json +++ b/frontend/syntaxmeets/package.json @@ -13,6 +13,7 @@ "axios": "^0.21.1", "bootstrap": "^4.5.3", "copy-to-clipboard": "^3.3.1", + "emoji-mart": "^3.0.1", "fontsource-poppins": "^3.0.9", "react": "^16.13.1", "react-ace": "^9.1.4", diff --git a/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js b/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js index e2f77cdd6..6b763934f 100644 --- a/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js +++ b/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js @@ -1,5 +1,6 @@ import React, { useState, useEffect, useRef } from "react"; import { makeStyles } from "@material-ui/core/styles"; +import InsertEmoticonIcon from "@material-ui/icons/InsertEmoticon"; import { Drawer, Button, @@ -13,6 +14,8 @@ import SendIcon from "@material-ui/icons/Send"; import ForumIcon from "@material-ui/icons/Forum"; import { ChatMessage } from "./ChatMessage"; import CloseSharpIcon from "@material-ui/icons/CloseSharp"; +import "emoji-mart/css/emoji-mart.css"; +import { Picker } from "emoji-mart"; const useStyles = makeStyles({ list: { @@ -28,12 +31,14 @@ const SyntaxChat = (props) => { const [message, setMessage] = useState(""); const [messages, setMessages] = useState([]); const [typingUser, setTypingUser] = useState(); + const [emojiPickerState, SetEmojiPicker] = useState(false); const messagesEndRef = useRef(null); const [mCount, setMCount] = useState(0); const [state, setState] = useState(false); const handleMessageSubmit = () => { + SetEmojiPicker(false); if (message === "") return; let data = { name: props.name, @@ -69,7 +74,22 @@ const SyntaxChat = (props) => { } }; + function triggerPicker(event) { + event.preventDefault(); + SetEmojiPicker(!emojiPickerState); + } useEffect(scrollToBottom, [messages]); + let emojiPicker; + if (emojiPickerState) { + emojiPicker = ( + setMessage(message + emoji.native)} + // style={{width: "90%", display: "flex"}} + /> + ); + } const toggleDrawer = (open) => (event) => { if ( @@ -151,7 +171,26 @@ const SyntaxChat = (props) => { ) : undefined} - + {/* */} + + {/* */} + + + {/* */} + + { } }} /> + {/* SetMessage(event.target.value)} + /> */} + + + {emojiPicker} + + From 1010f87825c76d5c380669f05a4a94c815172c43 Mon Sep 17 00:00:00 2001 From: Priyankcoder Date: Thu, 25 Mar 2021 17:51:45 +0530 Subject: [PATCH 6/8] tweak styling --- .../src/components/SyntaxChat/SyntaxChat.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js b/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js index 6b763934f..adf9b1f47 100644 --- a/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js +++ b/frontend/syntaxmeets/src/components/SyntaxChat/SyntaxChat.js @@ -170,9 +170,9 @@ const SyntaxChat = (props) => { ) : undefined} - + {/* */} - + {/*