-
Notifications
You must be signed in to change notification settings - Fork 317
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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={() => <Ques theme={theme} />} | ||
/> | ||
<Route | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more Efficient for Data Handling There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
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}`, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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; | ||
} |
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"; | ||
|
@@ -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} | ||
</button> | ||
<button> | ||
<Link to={`/getanswers/${item._id}`}>Get Answer</Link> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -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> | ||
|
There was a problem hiding this comment.
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