Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate-Answers-in-QA-Page - Added Small Code #939

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't push .env changes

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a separate route for answers?? each question should have a list of answers right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more Efficient for Data Handling

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directing to a new page for answers doesn't make sense, either make it collapsible(like FAQ page) or open a pop-up and show the question and all its answers,

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}`, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add page loader and generic toast message Which should show success message on success and failure message on failure.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove console log statement.


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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead to directing to a different page, make it like a pop-up, (check Broadcast page for reference)

</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
Loading