Skip to content

Commit

Permalink
Q&A page fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BHS-Harish committed Jul 31, 2024
1 parent 74914d2 commit 24dc68a
Showing 1 changed file with 59 additions and 50 deletions.
109 changes: 59 additions & 50 deletions frontend/src/pages/Q&A/Q&A.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ function Ques(props) {
}
};

const filterApprovedQuestions = (questions) => {
return questions.filter((question) => question.isApproved == true)
}

const [getQuestions, setQuestions] = useState([]);
const fetchQuestions = () => {
getAllQuestion(setToast).then((data) => {
setLoading(false);
setLoading(true);
data = data.map((item) => {
return { ...item, tags: item.tags[0] };
});
setQuestions(data);
setQuestions(filterApprovedQuestions(data));
});
};

Expand All @@ -144,6 +148,7 @@ function Ques(props) {
};

useEffect(() => {
setLoading(false)
fetchQuestions();
}, []);

Expand All @@ -152,55 +157,59 @@ function Ques(props) {
className="popup-creator"
style={{ background: dark ? "#171717" : "white" }}
>
{getQuestions.length <= 0 ? (
<Loader />
) : (
<div className="question-cards">
{getQuestions?.map((item, key) => {
let tags = [...Object.values(item.tags)];
return (
<div className="question-card" key={key}>
<div className="card-up">
<p>{item.title}</p>
<p>{item.description}</p>
<div className="tags-container">
{tags.map((i, index) => {
if (i == true)
return (
<span className="tag-space" key={index}>
{i === true ? `#${Tags[index].value}` : ""}
</span>
);
})}
</div>
</div>
<div className="card-down">
<div>
<p>
Created At {new Date(item.createdAt).toLocaleString()}
</p>
</div>
<div>
<button
className="vote-btn"
onClick={() => handleUpvote(item._id)}
>
πŸ‘{item.upvotes}
</button>
<button
className="vote-btn"
onClick={() => handleDownvote(item._id)}
>
πŸ‘Ž {item?.downvotes}
</button>
{
!loading ?
<Loader /> :
getQuestions.length == 0 ?
<div>
<h1 className="py-5 text-center">No Questions Found !</h1>
</div>
:
<div className="question-cards">
{getQuestions?.map((item, key) => {
let tags = [...Object.values(item.tags)];
return (
<div className="question-card" key={key}>
<div className="card-up">
<p>{item.title}</p>
<p>{item.description}</p>
<div className="tags-container">
{tags.map((i, index) => {
if (i == true)
return (
<span className="tag-space" key={index}>
{i === true ? `#${Tags[index].value}` : ""}
</span>
);
})}
</div>
</div>
<div className="card-down">
<div>
<p>
Created At {new Date(item.createdAt).toLocaleString()}
</p>
</div>
<div>
<button
className="vote-btn"
onClick={() => handleUpvote(item._id)}
>
πŸ‘{item.upvotes}
</button>
<button
className="vote-btn"
onClick={() => handleDownvote(item._id)}
>
πŸ‘Ž {item?.downvotes}
</button>
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
)}

);
})}
</div>
}
{toast.toastStatus && (
<SimpleToast
open={toast.toastStatus}
Expand Down

0 comments on commit 24dc68a

Please sign in to comment.