Skip to content

Commit

Permalink
Merge pull request #13 from zakie2003/zakie-pr-wala
Browse files Browse the repository at this point in the history
Nav Bar question displayed
  • Loading branch information
nishant0708 authored Sep 16, 2024
2 parents ca0559c + b07ad24 commit 3988d89
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,11 @@
cursor: pointer;
background-color: #4caf4f62;
border-color: #4caf4f62;
}

.question-description
{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
40 changes: 35 additions & 5 deletions src/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Navbar = () => {
const [timeLeft, setTimeLeft] = useState(0);
const [studentDetails, setStudentDetails] = useState({ fullName: "", rollNumber: "" });
const paperId = localStorage.getItem("paperId");
const [questionList, setQuestionList] = useState([]);
const studentId = localStorage.getItem("studentId");
const { questionId } = useParams(); // Extract questionId from the URL

Expand All @@ -35,6 +36,7 @@ const Navbar = () => {
try {
const response = await axios.post('http://localhost:5000/paper/getReadyPaperDetailsByPaperId', { paperId });
const paper = response.data[0];
// console.log(paper);
const endTime = new Date(paper.endTime);
const currentTime = new Date();
const remainingTime = Math.floor((endTime - currentTime) / 1000);
Expand All @@ -44,6 +46,19 @@ const Navbar = () => {
}
};

const fetchQuestionDetails = async () => {
try {
let response = await axios.post('http://localhost:5000/student/getQuestionByPaperId', { paperId });

let sortedQuestions = response.data.questions.sort((a, b) => a.marks - b.marks);

setQuestionList(sortedQuestions);
} catch (error) {
console.error("Error fetching question details:", error);
}
};


// Fetch student details using studentId
const fetchStudentDetails = async () => {
try {
Expand Down Expand Up @@ -73,13 +88,13 @@ const Navbar = () => {
useEffect(() => {
fetchPaperDetails();
fetchStudentDetails();

fetchQuestionDetails();
const countdown = setInterval(() => {
setTimeLeft((prevTime) => (prevTime > 0 ? prevTime - 1 : 0));
}, 1000);

return () => clearInterval(countdown);
}, []);
},[]);

return (
<>
Expand Down Expand Up @@ -121,9 +136,24 @@ const Navbar = () => {
<div className={`sidebar ${sidebarOpen ? "open" : ""}`}>
<RxCross2 onClick={toggleSidebar} className="slidebar-back-icon" />
<ul className="question-list">
<div className="slidebar-ele">Question 1</div>
<div className="slidebar-ele">Question 2</div>
<div className="slidebar-ele">Question 3</div>
{
questionList.map((question,index=0) => {
return <div onClick={() => window.location.href = `/compiler/${question._id}`}
className="slidebar-ele"
key={index}>
<span className="question-heading">
{question.questionheading}
</span>
<span style={{float:"right"}} className="question-marks">
Marks: {question.marks}
</span>
<p className="question-description">
{question.questionDescription}
</p>
</div>
})
}

</ul>
</div>
{sidebarOpen && <div className="overlay" onClick={toggleSidebar}></div>}
Expand Down

0 comments on commit 3988d89

Please sign in to comment.