import React, { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { CircleNotchIcon } from '@phosphor-icons/react'; import { Course } from '../types'; import { getMyLearningCourses } from '../services/db'; import { CourseCard, Cover, Thumb } from '../components/catalog/Artwork'; import { PlayMockIcon } from '../components/ui/MockupIcons'; import { useSavedCourses } from '../hooks/useSavedCourses'; import { useCatalog } from '../context/CatalogContext'; import { useIsMobile } from '../hooks/useMediaQuery'; import { paths } from '../lib/routes'; export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () => { const [courses, setCourses] = useState([]); const [loading, setLoading] = useState(true); const [tab, setTab] = useState<'andamento' | 'concluidos' | 'salvos'>('andamento'); const saved = useSavedCourses(); const isMobile = useIsMobile(); const { courses: catalogCourses } = useCatalog(); useEffect(() => { getMyLearningCourses().then(setCourses).catch(() => setCourses([])).finally(() => setLoading(false)); }, []); const going = courses.filter((course) => (course.progress || 0) < 100); const done = courses.filter((course) => (course.progress || 0) >= 100); const savedCourses = catalogCourses.filter((course) => saved.isSaved(course.id)); const first = going[0]; const completedCount = first ? Math.round(((first.progress || 0) / 100) * first.lessons.length) : 0; const nextLesson = first?.lessons[Math.min(completedCount, Math.max(first.lessons.length - 1, 0))]; if (loading) return
; if (isMobile) { const chosen = tab === 'andamento' ? going : tab === 'concluidos' ? done : savedCourses; return

Minha aprendizagem

{[['andamento', 'Em andamento'], ['concluidos', 'Concluídos'], ['salvos', 'Salvos']].map(([key, label]) => )}
{chosen.length ?
{chosen.map((course) => { const progress = course.progress || 0; const lessonIndex = Math.min(Math.round((progress / 100) * course.lessons.length), Math.max(course.lessons.length - 1, 0)); const linkedLesson = course.lessons[lessonIndex]; const to = tab === 'andamento' && linkedLesson ? paths.lesson(course.id, linkedLesson.id) : paths.course(course.id); const sub = tab === 'andamento' ? `Aula ${lessonIndex + 1} de ${course.lessons.length}` : tab === 'concluidos' ? 'Concluído' : `${course.lessons.length} aulas`; return {course.title}{sub}{tab === 'andamento' && }; })}
:

Nada por aqui ainda.

}
; } return

Minha aprendizagem

{first &&

{nextLesson?.title || first.title}

Continuar de onde parou · {first.title}, aula {Math.min(completedCount + 1, first.lessons.length)} de {first.lessons.length}

Continuar }

Em andamento

{going.map((course) => )}

Concluídos

{done.map((course) => )}

Salvos

{savedCourses.map((course) => )}
; };