diff --git a/resources/js/Pages/Courses/Player.tsx b/resources/js/Pages/Courses/Player.tsx index b73af61..d207249 100644 --- a/resources/js/Pages/Courses/Player.tsx +++ b/resources/js/Pages/Courses/Player.tsx @@ -1,6 +1,6 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; import { Head, Link, router } from '@inertiajs/react'; -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { Plyr } from 'plyr-react'; import 'plyr-react/plyr.css'; import { @@ -68,6 +68,7 @@ interface CurrentLessonData { video_url: string | null; content_pdf: string | null; vocabularies: VocabularyData[]; + is_completed?: boolean; } interface ProgressData { @@ -83,6 +84,7 @@ interface PlayerProps { auth: { user: any; }; + [key: string]: any; } // Helper to get YouTube video ID @@ -93,33 +95,13 @@ function getYouTubeId(url: string | null): string | null { return (match && match[2].length === 11) ? match[2] : null; } -export default function Player({ course, currentLesson, progress, auth }: PlayerProps) { - const [sidebarOpen, setSidebarOpen] = useState(true); - const [isPlaying, setIsPlaying] = useState(null); - - const handleComplete = () => { - router.post(route('lessons.complete', { lesson: currentLesson.id })); - }; - - const playAudio = (url: string, id: string) => { - const audio = new Audio(url); - setIsPlaying(id); - audio.play(); - audio.onended = () => setIsPlaying(null); - }; - - const videoSource = currentLesson.video_url ? { - type: 'video' as const, - sources: [{ - src: getYouTubeId(currentLesson.video_url) || currentLesson.video_url, - provider: currentLesson.video_url.includes('youtube') ? 'youtube' as const : 'html5' as const, - }], - } : null; - - const NavigationContent = () => ( +/** + * Sub-component for Navigation Content + */ +function NavigationContent({ course, currentLesson }: { course: CourseData, currentLesson: CurrentLessonData }) { + return (

Daftar Materi

-
{course.modules.map((module) => (
@@ -131,6 +113,7 @@ export default function Player({ course, currentLesson, progress, auth }: Player {module.lessons.map((lesson) => (
  • ); +} + +export default function Player({ course, currentLesson, progress, auth }: PlayerProps) { + const [sidebarOpen, setSidebarOpen] = useState(true); + const [isPlaying, setIsPlaying] = useState(null); + + const handleComplete = () => { + // @ts-ignore + router.post(route('lessons.complete', { lesson: currentLesson.id })); + }; + + const playAudio = (url: string, id: string) => { + const audio = new Audio(url); + setIsPlaying(id); + audio.play(); + audio.onended = () => setIsPlaying(null); + }; + + const videoSource = currentLesson.video_url ? { + type: 'video' as const, + sources: [{ + src: getYouTubeId(currentLesson.video_url) || currentLesson.video_url, + provider: currentLesson.video_url.includes('youtube') ? 'youtube' as const : 'html5' as const, + }], + } : null; return (
    - +
    @@ -193,7 +205,7 @@ export default function Player({ course, currentLesson, progress, auth }: Player

    Kurikulum Kursus

    - +
    @@ -229,7 +241,7 @@ export default function Player({ course, currentLesson, progress, auth }: Player {currentLesson.is_completed && Completed}

    - +

    @@ -237,10 +249,8 @@ export default function Player({ course, currentLesson, progress, auth }: Player {/* Text Content */} {currentLesson.type === 'text' && currentLesson.content && (
    -
    - {/* Ideally we'd have a parser for the whole content HTML too, - but for now we trust the seeder gives us plain text with furigana markers or HTML */} - +
    +
    )} @@ -250,14 +260,14 @@ export default function Player({ course, currentLesson, progress, auth }: Player