Skip to content

Commit

Permalink
user can post answer now
Browse files Browse the repository at this point in the history
  • Loading branch information
effy971 committed Dec 14, 2020
1 parent 25d2e66 commit 5984578
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 0 additions & 1 deletion answerquestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = async function (answer, userName, id) {
upsert: true,
}
);
console.log(result);
} finally {
await client.close();
return true;
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/Components/Question/AnswerModal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import React from "react";
import { useState } from "react";
import "./AnswerModal.css";

const AnswerModal = (props) => {
const [answer, setAnswer] = useState("");

const handleClickAnswer = () => {
fetch("/answerquestion", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: props.id,
userName: document.cookie
.split("; ")
.find((row) => row.startsWith("access-token"))
.split("=")[1],
answer: answer,
}),
});

alert("Answer Submitted");
setTimeout(window.location.reload(true), 2500);
};

return (
<div className="outer-answer">
<dialog open>
Expand Down Expand Up @@ -29,10 +50,14 @@ const AnswerModal = (props) => {
))
)}

<textarea value="enter you answer here!"></textarea>
<textarea
value={answer}
placeholder="enter you answer here!"
onChange={(e) => setAnswer(e.target.value)}
></textarea>
<div className="buttons">
<button onClick={props.exit}>Exit</button>
<button>Submit</button>
<button onClick={handleClickAnswer}>Submit</button>
</div>
</dialog>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/Components/Question/QuestionTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const QuestionTitle = (props) => {
<br />
{modal ? (
<AnswerModal
id={props.id}
exit={handleClickExit}
answer={props.answer}
tags={props.tags}
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ app.get("/answerquestion", async (req, res) => {
res.json(result);
});

app.post("/answerquestion", async (req, res) => {
app.put("/answerquestion", async (req, res) => {
const id = req.body.id;
const userName = jwt_decode(req.body.userName).userName;
const answer = req.body.answer;
console.log(answer);
console.log(answer, userName, id);

const result = await answerQuestion(answer, userName, id);

res.send("success");
res.send("answer received");
});

app.get("/queryworkspace", async (req, res) => {
Expand Down

0 comments on commit 5984578

Please sign in to comment.