From 9b77bdfdf9f5dc110c6749df54b017a35bf310eb Mon Sep 17 00:00:00 2001 From: "j.mei7" Date: Sun, 3 Apr 2022 18:03:33 +0200 Subject: [PATCH] create idea --- express_backend/database.db | Bin 212992 -> 212992 bytes express_backend/server.js | 23 +++++++++++++++++++++-- react_frontend/src/Idea.js | 2 +- react_frontend/src/IdeaContent.js | 2 +- react_frontend/src/IdeaList.js | 16 +++++++++++++++- react_frontend/src/css/App.scss | 3 ++- react_frontend/src/css/IdeaContent.scss | 3 ++- react_frontend/src/css/index.scss | 21 +++++++++++++++++++++ 8 files changed, 63 insertions(+), 7 deletions(-) diff --git a/express_backend/database.db b/express_backend/database.db index 9e04cfcb5662b7f498ba847f8c9dc09d9235e143..7b07dff9686b165af713706ec4224a457ea2034c 100644 GIT binary patch delta 647 zcmZo@;B9E&ogmHVGEv5v(Pd-85`IlVJ{eB_E&R#+v-z9&z4#6J#rgj7J>fgew~22i zUjtt{pC6wopG?PJ&&~aU5saH#1*h}Wiwm+a$SV7#mMeIsq$YxB=lr~q)VvaL0bCON zxFq;+N$}#5;Hk$Y!;MRV3zq~Z4habk76y5s4@*-)UQ9*uq69ljJ%g+&7S9`rv*9pJ zoE3+J1QQE`xOPZpNlvPQf4vcLMOaP&Pr`G@g delta 268 zcmZo@;B9E&ogmF=557H`xJ z$t=l%%4GuO%JXw_N>UYa6LS<&lTz~(a07k`CKd*9h<>1|#Nw30D-~i&4GfIT`QJ)0 zm@76~x|aft@=PgCO-%txr}#6nFhqw=J}56T`J6mEn;wWO4CR^uJ@$=({}2DS&4LC` Y_$LOiZT_auDZt3o console.log(`Listening on port ${port}`)); -app.get('/idea/:id', (req, res) => { +app.get('/idea/get/:id', (req, res) => { db.all(`SELECT * FROM ideas WHERE id = ${req.params.id}`, (err, rows) => { if (err) { @@ -42,7 +42,7 @@ app.get('/idea/:id', (req, res) => { }); app.get('/ideas', (req, res) => { - db.all(`SELECT * FROM ideas`, (err, rows) => { + db.all(`SELECT * FROM ideas ORDER BY id DESC`, (err, rows) => { if (err) { res.send({title: "Error", content: "Error fetching ideas"}); }else{ @@ -94,4 +94,23 @@ app.post('/idea/update/:id', (req, res) => { res.send({title: "Success", type:"saving", message: "Idea updated"}); } }); +}); + +app.get('/idea/create', (req, res) => { + console.log("CREATE") + // Create new idea + db.run(`INSERT INTO ideas (title, content) VALUES ('New Idea', 'New Content')`, (err) => { + if (err) { + res.send({title: "Error", type:"create", message: "Error creating new idea"}); + }else{ + // SELECT id from last idea + db.all(`SELECT * FROM ideas ORDER BY id DESC LIMIT 1`, (err, rows) => { + if (err) { + res.send({title: "Error", type:"create", message: "Error fetching new idea id"}); + }else{ + res.send({title: "Success", type:"create", id:rows[0].id, message: "New idea created"}); + } + }); + } + }); }); \ No newline at end of file diff --git a/react_frontend/src/Idea.js b/react_frontend/src/Idea.js index 42114cf..e89f262 100644 --- a/react_frontend/src/Idea.js +++ b/react_frontend/src/Idea.js @@ -9,7 +9,7 @@ function Idea({ideaId, title, description, timestamp}){ const fetchIdea = async () => { const data = await fetch( - 'http://localhost:5000/idea/' + params.ideaId + 'http://localhost:5000/idea/get/' + params.ideaId ); const idea = await data.json(); diff --git a/react_frontend/src/IdeaContent.js b/react_frontend/src/IdeaContent.js index 005d836..c1f3519 100644 --- a/react_frontend/src/IdeaContent.js +++ b/react_frontend/src/IdeaContent.js @@ -66,7 +66,7 @@ function IdeaContent(){ const fetchIdea = async () => { // fetch and check for error const data = await fetch( - 'http://localhost:5000/idea/' + params.ideaId + 'http://localhost:5000/idea/get/' + params.ideaId ); const idea = await data.json(); diff --git a/react_frontend/src/IdeaList.js b/react_frontend/src/IdeaList.js index 1488a9e..6b19433 100644 --- a/react_frontend/src/IdeaList.js +++ b/react_frontend/src/IdeaList.js @@ -9,6 +9,20 @@ function IdeaList() { let selectedIdeaId = params.ideaId; let [ideas, setIdeas] = useState([]); + const createIdea = async() => { + console.log('createIdea'); + + const data = await fetch( + 'http://localhost:5000/idea/create' + ); + + const result = await data.json(); + console.log(result) + if(result.title === "Success"){ + window.location = '/idea/' + result.id; + } + + } const fetchIdeas = async () => { const data = await fetch( 'http://localhost:5000/ideas/' @@ -32,7 +46,7 @@ function IdeaList() {
-

+

+

+

diff --git a/react_frontend/src/css/App.scss b/react_frontend/src/css/App.scss index a881ca9..491c907 100644 --- a/react_frontend/src/css/App.scss +++ b/react_frontend/src/css/App.scss @@ -2,9 +2,10 @@ display:block; background-color: rgb(32, 32, 32); width: 20%; - height: 100%; + height: 100vh; min-height: 100vh; float:left; + overflow: auto; } .content{ diff --git a/react_frontend/src/css/IdeaContent.scss b/react_frontend/src/css/IdeaContent.scss index 5db78b3..cb11b7a 100644 --- a/react_frontend/src/css/IdeaContent.scss +++ b/react_frontend/src/css/IdeaContent.scss @@ -49,9 +49,10 @@ } .textAreaContainer{ - width: 100%; + width: calc(100% - 10px); height: 700px; display: block; + padding-left: 10px; textarea{ outline: 0; diff --git a/react_frontend/src/css/index.scss b/react_frontend/src/css/index.scss index e4ac2d5..fa111d6 100644 --- a/react_frontend/src/css/index.scss +++ b/react_frontend/src/css/index.scss @@ -10,4 +10,25 @@ body, html{ background: #282727; min-height: 100%; +} + +// SCROLLBAR +* { + scrollbar-width: auto; + scrollbar-color: #62cba3 transparent; +} + +/* Chrome, Edge, and Safari */ +*::-webkit-scrollbar { + width: 5px; +} + +*::-webkit-scrollbar-track { + background: transparent; +} + +*::-webkit-scrollbar-thumb { + background-color: #62cba3; + border-radius: 10px; + border: 3px solid transparent; } \ No newline at end of file