Skip to content
Open
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
2 changes: 1 addition & 1 deletion course-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1 id="course-name">Course Name</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/course-content">Course Content</a></li>
<li><a href="/courses.html">Course Content</a></li>
<!-- Add more navigation links as needed -->
</ul>
</nav>
Expand Down
17 changes: 17 additions & 0 deletions courses.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courses</title>
</head>
<body>
<ul>
<li><a href="/course-content">Course 1</a></li>
<li><a href="/course-content">Course 2</a></li>
<li><a href="/course-content">Course 3</a></li>
<li><a href="/course-content">Course 4</a></li>
<li><a href="/course-content">Course 5</a></li>
</ul>
</body>
</html>
2 changes: 1 addition & 1 deletion dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Welcome to Your Dashboard</h1>
<nav>
<ul>
<li><a href="/leaderboard">Leaderboard</a></li>
<li><a href="/course-content">Course Content</a></li>
<li><a href="courses.html">Course Content</a></li>
<!-- Add more navigation links as needed -->
</ul>
</nav>
Expand Down
59 changes: 59 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,63 @@ function displayFullName(fullName) {
const fullNameElement = document.getElementById('user-fullname');
// Set the inner HTML of the element to the user's full name
fullNameElement.textContent = fullName;
}

function getUserId() {
return localStorage.getItem('user_id');
}

document.querySelectorAll('.course-select').forEach((courseSelect) => {
courseSelect.addEventListener('change', async (e) => {
const courseId = e.target.value;
const userId = getUserId();
try {
const response = await fetch('/select-course', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ userId, courseId })
});
if (response.ok) {
alert('Course selection successful');
} else {
alert('Course selection failed');
}
} catch (error) {
console.error('Error:', error);
}
});
});


function fetchSelectedCourses() {
const userId = getUserId();
fetch(`/selected-courses/${userId}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
displaySelectedCourses(data);
})
.catch(error => {
console.error('Error fetching selected courses:', error);
});
}

function displaySelectedCourses(selectedCourses) {
const selectedCoursesElement = document.getElementById('selected-courses');
selectedCoursesElement.innerHTML = '';
selectedCourses.forEach(course => {
const courseElement = document.createElement('div');
courseElement.textContent = course.name;
selectedCoursesElement.appendChild(courseElement);
});
}

if (window.location.pathname === '/selected-courses') {
fetchSelectedCourses();
}