-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate-Answers-in-QA-Page - Added Small Code
- Loading branch information
1 parent
8836396
commit 219ffad
Showing
5 changed files
with
107 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters