feat: Introduce core e-learning features with new pages for course details, dashboard, authentication, browsing, and learning, supported by a useCourse composable.

This commit is contained in:
supalerk-ar66 2026-01-23 09:47:32 +07:00
parent c982ab2c05
commit 0eb9b522f6
6 changed files with 109 additions and 38 deletions

View file

@ -11,9 +11,12 @@ definePageMeta({
})
const route = useRoute()
// courseId URL params ( integer)
const courseId = computed(() => parseInt(route.params.id as string))
const { fetchCourseById, enrollCourse } = useCourse()
// useAsyncData Server-side rendering (SSR)
// Key: 'course-{id}' cache ID
const { data: courseData, error, refresh } = await useAsyncData(`course-${courseId.value}`, () => fetchCourseById(courseId.value))
const course = computed(() => {
@ -22,18 +25,20 @@ const course = computed(() => {
const isEnrolling = ref(false)
// ""
const handleEnroll = async () => {
if (!course.value) return
if (isEnrolling.value) return
isEnrolling.value = true
// API
const res = await enrollCourse(course.value.id)
if (res.success) {
// Navigate to my-courses
// "" params enrolled=true
return navigateTo('/dashboard/my-courses?enrolled=true')
} else {
// Handle error (alert for now, could be toast)
// error alert ( Toast notification)
alert(res.error || 'Failed to enroll')
}