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

Nav Bar question displayed #13

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
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
Loading