feat: add reviews, notifications, notes and account hardening
This commit is contained in:
@@ -2,22 +2,46 @@ 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 { LearningStats, getLearningStats, getMyLearningCourses } from '../services/db';
|
||||
import { CourseCard, Cover, Thumb } from '../components/catalog/Artwork';
|
||||
import { PlayMockIcon } from '../components/ui/MockupIcons';
|
||||
import { Select } from '../components/ui/Select';
|
||||
import { useSavedCourses } from '../hooks/useSavedCourses';
|
||||
import { useCatalog } from '../context/CatalogContext';
|
||||
import { useIsMobile } from '../hooks/useMediaQuery';
|
||||
import { readPreference, writePreference } from '../lib/storage';
|
||||
import { paths } from '../lib/routes';
|
||||
|
||||
export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () => {
|
||||
const [courses, setCourses] = useState<Course[]>([]);
|
||||
const [stats, setStats] = useState<LearningStats | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [tab, setTab] = useState<'andamento' | 'concluidos' | 'salvos'>('andamento');
|
||||
const [weeklyGoal, setWeeklyGoal] = useState(() => {
|
||||
const stored = Number(readPreference('ca-weekly-goal'));
|
||||
return [3, 5, 7, 10].includes(stored) ? stored : 3;
|
||||
});
|
||||
const saved = useSavedCourses();
|
||||
const isMobile = useIsMobile();
|
||||
const { courses: catalogCourses } = useCatalog();
|
||||
useEffect(() => { getMyLearningCourses().then(setCourses).catch(() => setCourses([])).finally(() => setLoading(false)); }, []);
|
||||
useEffect(() => {
|
||||
getMyLearningCourses().then(setCourses).catch(() => setCourses([])).finally(() => setLoading(false));
|
||||
getLearningStats().then(setStats).catch(() => setStats(null));
|
||||
}, []);
|
||||
const updateGoal = (value: string) => {
|
||||
const next = Number(value);
|
||||
if (![3, 5, 7, 10].includes(next)) return;
|
||||
setWeeklyGoal(next);
|
||||
writePreference('ca-weekly-goal', String(next));
|
||||
};
|
||||
const formatWatchTime = (seconds: number) => {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
return hours ? `${hours}h ${minutes}min` : `${minutes}min`;
|
||||
};
|
||||
const weeklyCompleted = stats?.weeklyCompleted ?? 0;
|
||||
const goalPct = Math.min(100, Math.round((weeklyCompleted / weeklyGoal) * 100));
|
||||
const goalOptions = [3, 5, 7, 10].map((value) => ({ value: String(value), label: `${value} aulas` }));
|
||||
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));
|
||||
@@ -30,6 +54,13 @@ export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () =>
|
||||
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-stats num">
|
||||
<div><b>{stats?.streakDays ?? 0}</b><small>dias seguidos</small></div>
|
||||
<div><b>{Math.floor((stats?.watchedSeconds ?? 0) / 60)}</b><small>min assistidos</small></div>
|
||||
<div><b>{stats?.completedLessons ?? 0}</b><small>aulas concluídas</small></div>
|
||||
<div><b>{weeklyCompleted}/{weeklyGoal}</b><small>meta semanal</small></div>
|
||||
</div>
|
||||
<section className="m-group"><h2>Meta da semana</h2><div className="m-list"><div className="m-row"><span className="m-rt"><b className="num">{weeklyCompleted} de {weeklyGoal} aulas</b><small>{goalPct}% concluído</small></span><Select variant="mobile" value={String(weeklyGoal)} options={goalOptions} onChange={updateGoal} ariaLabel="Meta semanal de aulas" /></div></div><span className="m-bar" style={{ display: 'block', marginTop: 10 }}><i style={{ width: `${goalPct}%` }} /></span></section>
|
||||
<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;
|
||||
@@ -44,6 +75,12 @@ export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () =>
|
||||
|
||||
return <main className="wrap page enter">
|
||||
<div className="ptitle"><div><h1>Minha aprendizagem</h1></div></div>
|
||||
{stats && <div className="stats">
|
||||
<div><small>Sequência de estudos</small><b className="num">{stats.streakDays} {stats.streakDays === 1 ? 'dia' : 'dias'}</b></div>
|
||||
<div><small>Tempo assistido</small><b className="num">{formatWatchTime(stats.watchedSeconds)}</b></div>
|
||||
<div><small>Aulas concluídas</small><b className="num">{stats.completedLessons}</b></div>
|
||||
<div><small>Cursos com atividade</small><b className="num">{stats.activeCourses}</b></div>
|
||||
</div>}
|
||||
{first && <Link className="box contbox" to={paths.continueCourse(first.id)}>
|
||||
<Cover course={first} variant="mini" />
|
||||
<div>
|
||||
@@ -53,6 +90,11 @@ export const MyLearning: React.FC<{ onPlay: (course: Course) => void }> = () =>
|
||||
</div>
|
||||
<span className="btn"><PlayMockIcon className="ph" /> Continuar</span>
|
||||
</Link>}
|
||||
<div className="box week-goal">
|
||||
<div><h3>Meta da semana</h3><p className="small num">{weeklyCompleted} de {weeklyGoal} aulas concluídas</p></div>
|
||||
<Select value={String(weeklyGoal)} options={goalOptions} onChange={updateGoal} ariaLabel="Meta semanal de aulas" />
|
||||
<span className="prog"><i style={{ width: `${goalPct}%` }} /></span>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user