From 219ffad0107be7e821c9052d2f23b207f3704a9b Mon Sep 17 00:00:00 2001 From: tejasnasre Date: Mon, 20 May 2024 22:18:09 +0530 Subject: [PATCH] Integrate-Answers-in-QA-Page - Added Small Code --- backend/.env | 2 +- frontend/src/app.js | 6 ++ .../Q&A/Components/GetAnswer/GetAnswer.jsx | 74 +++++++++++++++++++ .../Q&A/Components/GetAnswer/GetAnswer.scss | 9 +++ frontend/src/pages/Q&A/Q&A.jsx | 31 ++++---- 5 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.jsx create mode 100644 frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.scss diff --git a/backend/.env b/backend/.env index b2ab43ac..1e4900f7 100644 --- a/backend/.env +++ b/backend/.env @@ -1,4 +1,4 @@ -MONGO_DB_URL= +MONGO_DB_URL=mongodb://localhost:27017/testdb JWT_SECRET_KEY= JWT_EXPIRES_IN=6h BASE_URL=https://community-website-backend.herokuapp.com diff --git a/frontend/src/app.js b/frontend/src/app.js index 88e73909..6e58ba0e 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -36,6 +36,7 @@ import { Broadcast } from "./pages/Broadcast/index"; import { AllBroadcasts } from "./pages/Broadcast/Component/AllBroadcasts/index"; import { GetInvolved } from "./pages/GetInvolved"; import { ForgotPasswordRecovery } from "./pages/ForgotPasswordRecovery/index"; +import GetAnswer from "./pages/Q&A/Components/GetAnswer/GetAnswer.jsx"; import { useSelector } from "react-redux"; @@ -132,6 +133,11 @@ const App = () => { path="/Q&A" render={() => } /> + } + /> { + try { + fetch(`${END_POINT}/answers/${answerId}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }) + .then((response) => response.json()) + .then((data) => { + console.log(data); + setAnswer(data.data); + }); + } catch (error) { + console.error("Error fetching answer:", error); + } + }; + useEffect(() => { + GetAnswer(answerId); + }, []); + + console.log(answer); + + return ( + <> +
+
question
+
+ {answer.length > 0 ? ( + answer.map((item, key) => ( +
+
+
+

{item.answer}

+ # +
+
+
+

+ Created At {new Date(item.createdAt).toLocaleString()} +

+

Created By {item.created_by}

+
+
+ + +
+
+
+
+ )) + ) : ( +

No Answer

+ )} +
+
+ + ); +} +export default GetAnswer; diff --git a/frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.scss b/frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.scss new file mode 100644 index 00000000..7c038e5b --- /dev/null +++ b/frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.scss @@ -0,0 +1,9 @@ +.main { + height: 100vh; + width: 100%; + background-color: #171717; + color: white; + display: flex; + flex-direction: column; + align-items: center; +} diff --git a/frontend/src/pages/Q&A/Q&A.jsx b/frontend/src/pages/Q&A/Q&A.jsx index f3be734e..754a96b0 100644 --- a/frontend/src/pages/Q&A/Q&A.jsx +++ b/frontend/src/pages/Q&A/Q&A.jsx @@ -1,4 +1,5 @@ import React, { useEffect } from "react"; +import { Link } from "react-router-dom"; import { Button2, Button1 } from "../../components/util/Button"; import style from "../Resources/components/ResourceSharingForm/resource-sharing-form.module.scss"; import "./Ques.scss"; @@ -7,11 +8,6 @@ import Joi from "joi-browser"; import Loader from "../../components/util/Loader/index"; import { SimpleToast } from "../../components/util/Toast"; import { END_POINT } from "../../config/api"; -import { - AirplayTwoTone, - ErrorSharp, - SettingsBluetoothSharp, -} from "@material-ui/icons"; function Ques(props) { let dark = props.theme; @@ -124,17 +120,17 @@ function Ques(props) { body: JSON.stringify(formdata), }); const data = await response.json(); - if(data.errStack){ + if (data.errStack) { setToastMessage(`${data.errStack}`); setOpenToast(true); setSeverity("error"); - }else{ + } else { setToastMessage("Q&A added successfully!"); setOpenToast(true); setSeverity("success"); } setIsUploadingData(false); - + setFormData({ title: "", description: "", @@ -273,6 +269,9 @@ function Ques(props) { > 👎 {item.downvote} + @@ -428,12 +427,16 @@ function Ques(props) { style={{ justifyContent: "space-around" }} >
- {isUploadingData ? : } + {isUploadingData ? ( + + ) : ( + + )}