feat: finalize academy redesign and production readiness
Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
This commit is contained in:
@@ -1,40 +1,60 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { BookOpenCheck, Loader2, PlayCircle } from 'lucide-react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { CircleNotchIcon } from '@phosphor-icons/react';
|
||||
import { Course } from '../types';
|
||||
import { getMyLearningCourses } from '../services/db';
|
||||
import { CourseCoverImage } from '../components/CourseCoverImage';
|
||||
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 }> = ({ onPlay }) => {
|
||||
export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () => {
|
||||
const [courses, setCourses] = useState<Course[]>([]);
|
||||
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))];
|
||||
|
||||
useEffect(() => {
|
||||
getMyLearningCourses().then(setCourses).catch(() => setCourses([])).finally(() => setLoading(false));
|
||||
}, []);
|
||||
if (loading) return <main className="wrap page enter"><div className="loading"><CircleNotchIcon className="ph spin" /></div></main>;
|
||||
|
||||
return (
|
||||
<main className="min-h-screen max-w-[1440px] mx-auto pt-28 pb-20 px-6 md:px-12">
|
||||
<div className="mb-10">
|
||||
<div className="flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-orange-400 mb-3"><BookOpenCheck className="w-4 h-4" /> Minha área</div>
|
||||
<h1 className="text-3xl md:text-4xl font-bold text-white">Continue aprendendo</h1>
|
||||
<p className="mt-2 text-gray-400">Retome suas aulas exatamente de onde parou.</p>
|
||||
if (isMobile) {
|
||||
const chosen = tab === 'andamento' ? going : tab === 'concluidos' ? done : savedCourses;
|
||||
return <main className="m-page m-gut enter"><header className="m-large"><h1>Minha aprendizagem</h1></header>
|
||||
<div className="m-seg" role="tablist">{[['andamento', 'Em andamento'], ['concluidos', 'Concluídos'], ['salvos', 'Salvos']].map(([key, label]) => <button type="button" role="tab" key={key} aria-selected={tab === key} onClick={() => setTab(key as typeof tab)}>{label}</button>)}</div>
|
||||
{chosen.length ? <section className="m-group"><div className="m-list">{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 <Link className="m-row" key={course.id} to={to}><Thumb course={course} className="m-th" /><span className="m-rt"><b>{course.title}</b><small>{sub}</small></span>{tab === 'andamento' && <span className="m-mini"><span className="m-bar"><i style={{ width: `${progress}%` }} /></span></span>}</Link>;
|
||||
})}</div></section> : <p className="m-empty">Nada por aqui ainda.</p>}
|
||||
</main>;
|
||||
}
|
||||
|
||||
return <main className="wrap page enter">
|
||||
<div className="ptitle"><div><h1>Minha aprendizagem</h1></div></div>
|
||||
{first && <Link className="box contbox" to={paths.continueCourse(first.id)}>
|
||||
<Cover course={first} variant="mini" />
|
||||
<div>
|
||||
<h2>{nextLesson?.title || first.title}</h2>
|
||||
<p className="num" style={{ fontSize: 14, color: 'var(--fg-2)', marginTop: 4 }}>Continuar de onde parou · {first.title}, aula {Math.min(completedCount + 1, first.lessons.length)} de {first.lessons.length}</p>
|
||||
<div className="prog"><i style={{ width: `${Math.round(first.progress || 0)}%` }} /></div>
|
||||
</div>
|
||||
{loading ? <div className="h-64 flex justify-center items-center"><Loader2 className="w-8 h-8 animate-spin text-orange-400" /></div> : courses.length === 0 ? (
|
||||
<div className="rounded-2xl border border-white/10 bg-zinc-950/80 py-16 px-6 text-center">
|
||||
<BookOpenCheck className="w-10 h-10 text-orange-400 mx-auto mb-4" />
|
||||
<h2 className="font-bold text-white text-lg">Você ainda não iniciou nenhum curso</h2>
|
||||
<p className="mt-2 text-sm text-gray-400">Escolha uma aula na página de cursos para começar.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-5">
|
||||
{courses.map((course) => (
|
||||
<button key={course.id} onClick={() => onPlay(course)} className="group overflow-hidden rounded-2xl border border-white/10 bg-zinc-950/80 text-left hover:border-orange-500/50 transition-colors">
|
||||
<div className="aspect-video relative overflow-hidden bg-zinc-900"><CourseCoverImage source={course.thumbnail} alt="" className="h-full w-full object-cover opacity-75 transition-opacity group-hover:opacity-100" style={{ transform: `scale(${course.coverImageZoom || 1})`, objectPosition: `${course.coverImagePositionX ?? 50}% ${course.coverImagePositionY ?? 50}%` }} /><div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent" /><span className="absolute left-4 bottom-4 inline-flex items-center gap-2 rounded-full bg-orange-500 px-3 py-2 text-xs font-bold text-white"><PlayCircle className="w-4 h-4" /> Continuar</span></div>
|
||||
<div className="p-5"><p className="text-xs text-orange-400 font-semibold uppercase tracking-wider">{course.category}</p><h2 className="mt-2 font-bold text-white">{course.title}</h2><div className="mt-4 h-1.5 overflow-hidden rounded-full bg-white/10"><div className="h-full rounded-full bg-orange-500" style={{ width: `${course.progress || 0}%` }} /></div><p className="mt-2 text-xs text-gray-400">{course.progress || 0}% concluído</p></div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
<span className="btn"><PlayMockIcon className="ph" /> Continuar</span>
|
||||
</Link>}
|
||||
<section className="shelf"><header><h2>Em andamento</h2></header><div className="grid">{going.map((course) => <CourseCard key={course.id} course={course} />)}</div></section>
|
||||
<section className="shelf"><header><h2>Concluídos</h2></header><div className="grid">{done.map((course) => <CourseCard key={course.id} course={course} />)}</div></section>
|
||||
<section className="shelf"><header><h2>Salvos</h2></header><div className="grid">{savedCourses.map((course) => <CourseCard key={course.id} course={course} />)}</div></section>
|
||||
</main>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user