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:
61
pages/CommunityPage.tsx
Normal file
61
pages/CommunityPage.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { CaretRightIcon, PlusIcon } from '@phosphor-icons/react';
|
||||
import { Comment, Course } from '../types';
|
||||
import { getCommunityComments } from '../services/db';
|
||||
import { useCatalog } from '../context/CatalogContext';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { Avatar } from '../components/ui/Avatar';
|
||||
import { ChatMockIcon, PlusMockIcon, TeacherMockIcon } from '../components/ui/MockupIcons';
|
||||
import { paths } from '../lib/routes';
|
||||
import { useIsMobile } from '../hooks/useMediaQuery';
|
||||
|
||||
type Thread = { comment: Comment; course: Course };
|
||||
|
||||
const lessonNumberFor = (comment: Comment, course: Course) => {
|
||||
if (!comment.lessonId) return 0;
|
||||
return course.lessons.findIndex((lesson) => lesson.id === comment.lessonId) + 1;
|
||||
};
|
||||
|
||||
export const CommunityPage: React.FC = () => {
|
||||
const { courses, professors } = useCatalog();
|
||||
const { user } = useAuth();
|
||||
const location = useLocation();
|
||||
const isMobile = useIsMobile();
|
||||
const [threads, setThreads] = useState<Thread[]>([]);
|
||||
const [view, setView] = useState<'discussoes' | 'professores'>(() => new URLSearchParams(location.search).get('tab') === 'professores' ? 'professores' : 'discussoes');
|
||||
const [filter, setFilter] = useState<'todas' | 'abertas' | 'professor'>('todas');
|
||||
useEffect(() => {
|
||||
const courseById = new Map(courses.map((course) => [course.id, course]));
|
||||
let cancelled = false;
|
||||
getCommunityComments(100).then((comments) => {
|
||||
if (cancelled) return;
|
||||
setThreads(comments.flatMap((comment) => {
|
||||
const course = courseById.get(comment.courseId);
|
||||
return course ? [{ comment, course }] : [];
|
||||
}));
|
||||
}).catch(() => { if (!cancelled) setThreads([]); });
|
||||
return () => { cancelled = true; };
|
||||
}, [courses]);
|
||||
useEffect(() => { if (new URLSearchParams(location.search).get('tab') === 'professores') setView('professores'); }, [location.search]);
|
||||
const visible = threads.filter(({ comment }) => filter === 'todas' || (filter === 'abertas' ? !comment.reply : Boolean(comment.reply)));
|
||||
if (isMobile) return <main className="m-page m-gut enter"><header className="m-large"><h1>Comunidade</h1>{user && view === 'discussoes' && <Link className="m-icb" to={courses[0] ? paths.course(courses[0].id) : paths.explore} aria-label="Nova pergunta"><PlusIcon className="ph" /></Link>}</header>
|
||||
<div className="m-seg" role="tablist"><button type="button" role="tab" aria-selected={view === 'discussoes'} onClick={() => setView('discussoes')}>Discussões</button><button type="button" role="tab" aria-selected={view === 'professores'} onClick={() => setView('professores')}>Professores</button></div>
|
||||
{view === 'professores' ? <section className="m-group"><div className="m-list">{professors.map((professor) => <Link className="m-row" key={professor.id} to={paths.professor(professor.id)}><Avatar name={professor.name} src={professor.avatarImageUrl} size="sm" /><span className="m-rt"><b>{professor.name}</b><small>{professor.headline ? `${professor.headline} · ` : ''}{professor.courses.length} {professor.courses.length === 1 ? 'curso' : 'cursos'}</small></span><CaretRightIcon className="m-chev" /></Link>)}</div></section> : <><div className="m-chips" role="group" aria-label="Filtrar discussões">{[['todas', 'Todas'], ['abertas', 'Sem resposta'], ['professor', 'Com professor']].map(([key, label]) => <button key={key} type="button" aria-pressed={filter === key} onClick={() => setFilter(key as typeof filter)}>{label}</button>)}</div><section className="m-group"><div className="m-list multi">{visible.map(({ comment, course }) => <Link className="m-row" key={comment.id} to={comment.lessonId ? paths.lesson(course.id, comment.lessonId) : paths.course(course.id)}><Avatar name={comment.user} size="sm" /><span className="m-rt"><b>{comment.text}</b><small>{comment.user} · {course.title} · {comment.date}</small></span>{comment.reply && <span className="m-chev" aria-label="Professor respondeu"><TeacherMockIcon className="ph" /></span>}</Link>)}</div>{!visible.length && <p className="m-empty">Nenhuma discussão por aqui ainda.</p>}</section></>}
|
||||
</main>;
|
||||
return <main className="wrap page enter">
|
||||
<header className="ptitle"><div><h1>Discussões</h1><p>Perguntas e resultados dos alunos, organizados por aula.</p></div>{user ? <Link className="btn" to={courses[0] ? paths.course(courses[0].id) : paths.explore}><PlusMockIcon className="ph" /> Nova pergunta</Link> : <Link className="btn sec" to={paths.signIn}>Entrar para participar</Link>}</header>
|
||||
<div className="seg" role="group" aria-label="Filtrar discussões" style={{ marginBottom: 20 }}>
|
||||
{([['todas', 'Todas'], ['abertas', 'Sem resposta'], ['professor', 'Respondidas por professor']] as const).map(([key, label]) => <button key={key} type="button" aria-pressed={filter === key} onClick={() => setFilter(key)}>{label}</button>)}
|
||||
</div>
|
||||
<div className="list">{visible.map(({ comment, course }) => {
|
||||
const lessonNumber = lessonNumberFor(comment, course);
|
||||
return <Link className="row discussion-row" key={comment.id} to={comment.lessonId ? paths.lesson(course.id, comment.lessonId) : paths.course(course.id)}>
|
||||
<Avatar name={comment.user} size="sm" />
|
||||
<span className="t">{comment.text}<small>{[comment.user, `${course.title}${lessonNumber ? `, aula ${lessonNumber}` : ''}`, comment.date].join(' · ')}</small></span>
|
||||
<span className="r">{comment.reply && <span className="ic-prof" title="Professor respondeu" aria-label="Professor respondeu"><TeacherMockIcon className="ph" /></span>}<span className="ic-cnt" aria-label={`${comment.reply ? 1 : 0} respostas`}><ChatMockIcon className="ph" /> {comment.reply ? 1 : 0}</span></span>
|
||||
</Link>;
|
||||
})}</div>
|
||||
{!visible.length && <p className="empty">Nenhuma discussão por aqui ainda.</p>}
|
||||
</main>;
|
||||
};
|
||||
Reference in New Issue
Block a user