Skip to content

Commit

Permalink
Integrate-Answers-in-QA-Page - Added Small Code
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasNasre committed May 20, 2024
1 parent 8836396 commit 219ffad
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MONGO_DB_URL=<mongoDB_URL>
MONGO_DB_URL=mongodb://localhost:27017/testdb
JWT_SECRET_KEY=<JWT_sceret>
JWT_EXPIRES_IN=6h
BASE_URL=https://community-website-backend.herokuapp.com
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -132,6 +133,11 @@ const App = () => {
path="/Q&A"
render={() => <Ques theme={theme} />}
/>
<Route
exact={true}
path="/getanswers/:answerId"
render={() => <GetAnswer theme={theme} />}
/>
<Route
exact={true}
path="/admin"
Expand Down
74 changes: 74 additions & 0 deletions frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useEffect } from "react";
import { useState } from "react";
import "./GetAnswer.scss";
import "../../../Q&A/Ques.scss";
import { END_POINT } from "../../../../config/api";
import { useParams } from "react-router-dom";

function GetAnswer() {
const { answerId } = useParams();
// console.log(answerId);

const [answer, setAnswer] = useState([]);

//Get Answer
const GetAnswer = (answerId) => {
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 (
<>
<div className="main">
<div className="question">question</div>
<div className="answers">
{answer.length > 0 ? (
answer.map((item, key) => (
<div className="question-cards" key={key}>
<div className="question-card">
<div className="card-up">
<p>{item.answer}</p>
<span className="tag-space">#</span>
</div>
<div className="card-down">
<div>
<p>
Created At {new Date(item.createdAt).toLocaleString()}
</p>
<p>Created By {item.created_by}</p>
</div>
<div>
<button className="vote-btn">πŸ‘</button>
<button className="vote-btn">πŸ‘Ž</button>
</div>
</div>
</div>
</div>
))
) : (
<h1>No Answer</h1>
)}
</div>
</div>
</>
);
}
export default GetAnswer;
9 changes: 9 additions & 0 deletions frontend/src/pages/Q&A/Components/GetAnswer/GetAnswer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.main {
height: 100vh;
width: 100%;
background-color: #171717;
color: white;
display: flex;
flex-direction: column;
align-items: center;
}
31 changes: 17 additions & 14 deletions frontend/src/pages/Q&A/Q&A.jsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -273,6 +269,9 @@ function Ques(props) {
>
πŸ‘Ž {item.downvote}
</button>
<button>
<Link to={`/getanswers/${item._id}`}>Get Answer</Link>
</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -428,12 +427,16 @@ function Ques(props) {
style={{ justifyContent: "space-around" }}
>
<div className="data-loader">
{isUploadingData ? <Loader /> : <Button2
style={{ marginRight: "3%" }}
className={style["submit-btn-text"]}
label="Submit"
type="submit"
/>}
{isUploadingData ? (
<Loader />
) : (
<Button2
style={{ marginRight: "3%" }}
className={style["submit-btn-text"]}
label="Submit"
type="submit"
/>
)}
</div>
</div>
</div>
Expand Down

0 comments on commit 219ffad

Please sign in to comment.