From 692ca23398db6ff75e58576b89d23d8448b4a947 Mon Sep 17 00:00:00 2001 From: Anosh Malik Date: Wed, 17 May 2023 21:27:53 +0100 Subject: [PATCH 1/3] Corrected history page not loading bug Tested on 3 different github accounts and 2 different browsers separately History is retained on both browsers for all 3 users Co-Authored-By: Roman-Hal <85693082+Roman-Hal@users.noreply.github.com> Co-Authored-By: azadehroshan <105980239+azadehroshan@users.noreply.github.com> Co-Authored-By: Yousef Shaikhan <105981004+youweb3@users.noreply.github.com> --- client/src/Components/MainContent.js | 6 ++++-- client/src/pages/History.js | 5 ++++- server/api.js | 7 ++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/src/Components/MainContent.js b/client/src/Components/MainContent.js index 78fb9e5..e6614de 100644 --- a/client/src/Components/MainContent.js +++ b/client/src/Components/MainContent.js @@ -23,12 +23,13 @@ const MainContent = ({ user }) => { // SPEECH OUTPUT FEATURE useEffect(() => { + console.log(user); const synth = new SpeechSynthesisUtterance(); const voices = window.speechSynthesis.getVoices(); synth.voice = voices[0]; synth.lang = "en-GB"; setSynth(synth); - }, []); + }, [user]); // useEffect(() => { // // const synth = new SpeechSynthesisUtterance(); @@ -179,7 +180,7 @@ const MainContent = ({ user }) => { body: JSON.stringify({ input: content, output: response, - user_id: 3, + user_id: user.id, }), }) .then((res) => res.json()) @@ -218,6 +219,7 @@ const MainContent = ({ user }) => { onChange={(e) => { setContent(e.target.value); setResponse(""); + SetSaveCounter(1); }} style={{ boxShadow: "0px 5px 10px grey" }} /> diff --git a/client/src/pages/History.js b/client/src/pages/History.js index 0974242..b5ad977 100644 --- a/client/src/pages/History.js +++ b/client/src/pages/History.js @@ -17,7 +17,9 @@ const History = ({ user }) => { `http://localhost:3100/api/history?githubId=${user.id}&search=${search}&sort=${sort}` ) .then((response) => response.json()) - .then((data) => setHistory(data.data)) + .then((data) => { + setHistory(data.data); console.log(data.data); + }) .catch((error) => { console.log(error); }); @@ -25,6 +27,7 @@ const History = ({ user }) => { useEffect(() => { if (user) { + console.log(user); sendRequest(); } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/server/api.js b/server/api.js index 348a115..abd8fd3 100644 --- a/server/api.js +++ b/server/api.js @@ -79,6 +79,8 @@ router.get("/auth/login/success", (req, res) => { res.json(); throw new Error("no user"); } else { + // eslint-disable-next-line no-console + // console.log(req.session.user); res.json(req.session.user); } } catch (err) { @@ -227,9 +229,12 @@ router.post("/corrections", async (req, res) => { // Get all histories from db router.get("/history", (req, res) => { const { githubId, search, sort } = req.query; + // eslint-disable-next-line no-console + console.log("API > GITHUBID > " + githubId); if (githubId) { - let query = `SELECT history.* FROM users INNER JOIN history ON users.id = history.user_id AND users.github_id = ${githubId} `; + // let query = `SELECT history.* FROM users INNER JOIN history ON users.id = history.user_id AND users.github_id = ${githubId} `; + let query = `SELECT * FROM history WHERE user_id = ${githubId} `; if (search && search.length < 50) { query += ` AND ( history.input ~* '${search}' OR history.output ~* '${search}')`; } From 4faa2a0f7707ceaeecd36f201a5b899ad26bd71c Mon Sep 17 00:00:00 2001 From: Anosh Malik Date: Wed, 17 May 2023 21:36:17 +0100 Subject: [PATCH 2/3] lint_fix Co-Authored-By: Roman-Hal <85693082+Roman-Hal@users.noreply.github.com> Co-Authored-By: azadehroshan <105980239+azadehroshan@users.noreply.github.com> Co-Authored-By: Yousef Shaikhan <105981004+youweb3@users.noreply.github.com> --- client/src/pages/History.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/pages/History.js b/client/src/pages/History.js index b5ad977..878df4e 100644 --- a/client/src/pages/History.js +++ b/client/src/pages/History.js @@ -18,7 +18,8 @@ const History = ({ user }) => { ) .then((response) => response.json()) .then((data) => { - setHistory(data.data); console.log(data.data); + setHistory(data.data); + console.log(data.data); }) .catch((error) => { console.log(error); From 9560fa6c15279ee4f5e533f2eaccba9f7928dc19 Mon Sep 17 00:00:00 2001 From: Anosh Malik Date: Thu, 18 May 2023 11:35:12 +0100 Subject: [PATCH 3/3] Changes to the chatgpt prompt and removal of console.logs Co-Authored-By: Roman-Hal <85693082+Roman-Hal@users.noreply.github.com> Co-Authored-By: azadehroshan <105980239+azadehroshan@users.noreply.github.com> Co-Authored-By: Yousef Shaikhan <105981004+youweb3@users.noreply.github.com> --- client/src/Components/MainContent.js | 20 ++++++++++---------- client/src/pages/History.js | 4 ++-- server/api.js | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client/src/Components/MainContent.js b/client/src/Components/MainContent.js index e6614de..3b0916b 100644 --- a/client/src/Components/MainContent.js +++ b/client/src/Components/MainContent.js @@ -23,7 +23,7 @@ const MainContent = ({ user }) => { // SPEECH OUTPUT FEATURE useEffect(() => { - console.log(user); + // console.log(user); const synth = new SpeechSynthesisUtterance(); const voices = window.speechSynthesis.getVoices(); synth.voice = voices[0]; @@ -54,24 +54,24 @@ const MainContent = ({ user }) => { synth.text = "Here are your suggestions! " + response; } if (speechToggle % 2 == 0) { - console.log("Stopped"); + // console.log("Stopped"); SetSpeechToggle(speechToggle + 1); setIsIconPaused(false); window.speechSynthesis.cancel(); clearTimeout(timeOutId); - console.log("CLEAR TIMEOUT CALLED"); + // console.log("CLEAR TIMEOUT CALLED"); } else { - console.log("Playing"); + // console.log("Playing"); SetSpeechToggle(speechToggle + 1); setIsIconPaused(true); window.speechSynthesis.speak(synth); // FOLLOWING LINES ARE NEEDED TO STOP CHROME CUTTING AUDIO OFF AFTER 15 SECONDS window.speechSynthesis.pause(); - console.log("PAUSED"); + // console.log("PAUSED"); window.speechSynthesis.resume(); - console.log("RESUMED"); + // console.log("RESUMED"); // STOPS TEXT FROM LOOPING // synth.onend = () => { @@ -80,14 +80,14 @@ const MainContent = ({ user }) => { // clearTimeout(timeOutId); // }; if (window.speechSynthesis.speaking == false) { - console.log("Not speaking"); + // console.log("Not speaking"); window.speechSynthesis.cancel(); clearTimeout(timeOutId); } else { - console.log("Speaking"); + // console.log("Speaking"); let timeId = setTimeout(handleSpeak, 10000); SetTimeOutId(timeId); - console.log("SET TIMEOUT CALLED"); + // console.log("SET TIMEOUT CALLED"); } } } @@ -170,7 +170,7 @@ const MainContent = ({ user }) => { } else if (value === content && saveCounter > 1) { alert("Please update text on the left"); } else { - console.log(user.id); + // console.log(user.id); // const github_id = user.id; await fetch("/api/history", { method: "POST", diff --git a/client/src/pages/History.js b/client/src/pages/History.js index 878df4e..e0843e9 100644 --- a/client/src/pages/History.js +++ b/client/src/pages/History.js @@ -19,7 +19,7 @@ const History = ({ user }) => { .then((response) => response.json()) .then((data) => { setHistory(data.data); - console.log(data.data); + // console.log(data.data); }) .catch((error) => { console.log(error); @@ -28,7 +28,7 @@ const History = ({ user }) => { useEffect(() => { if (user) { - console.log(user); + // console.log(user); sendRequest(); } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/server/api.js b/server/api.js index abd8fd3..142d16f 100644 --- a/server/api.js +++ b/server/api.js @@ -207,7 +207,7 @@ router.post("/corrections", async (req, res) => { messages: [ { role: "user", - content: `Can you correct this sentence for grammatical issues and give it three options: ${text}`, + content: `Correct the sentence for grammar and spelling errors and suggest three alternatives in a list form: ${text}`, }, ], }); @@ -220,7 +220,7 @@ router.post("/corrections", async (req, res) => { }); //console.log(completion.data.choices[0].text);*/ // eslint-disable-next-line no-console - console.log(completion.data.choices[0].message); + // console.log(completion.data.choices[0].message); res.json({ msg: completion.data }); }); @@ -230,7 +230,7 @@ router.post("/corrections", async (req, res) => { router.get("/history", (req, res) => { const { githubId, search, sort } = req.query; // eslint-disable-next-line no-console - console.log("API > GITHUBID > " + githubId); + // console.log("API > GITHUBID > " + githubId); if (githubId) { // let query = `SELECT history.* FROM users INNER JOIN history ON users.id = history.user_id AND users.github_id = ${githubId} `; @@ -261,7 +261,7 @@ router.get("/history", (req, res) => { router.post("/history", (req, res) => { const { input, output, user_id } = req.body; // eslint-disable-next-line no-console - console.log("github id - " + user_id); + // console.log("github id - " + user_id); if (input && output && user_id) { db.query( // `INSERT INTO history(input ,output, user_id, timestamp ) VALUES ('${input}' ,'${output}','${user_id}', current_timestamp ) RETURNING id`