diff --git a/course-content.html b/course-content.html index d9b262e7..d314b47f 100644 --- a/course-content.html +++ b/course-content.html @@ -12,7 +12,7 @@

Course Name

diff --git a/courses.html b/courses.html new file mode 100644 index 00000000..89779cb2 --- /dev/null +++ b/courses.html @@ -0,0 +1,17 @@ + + + + + + Courses + + + + + \ No newline at end of file diff --git a/dashboard.html b/dashboard.html index ba3eb99e..8f792b82 100644 --- a/dashboard.html +++ b/dashboard.html @@ -12,7 +12,7 @@

Welcome to Your Dashboard

diff --git a/script.js b/script.js index 7293d9e6..eeedbec6 100644 --- a/script.js +++ b/script.js @@ -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(); } \ No newline at end of file