feat: add reviews, notifications, notes and account hardening
This commit is contained in:
@@ -358,6 +358,7 @@ export const ManageCourses: React.FC = () => {
|
||||
const [editingCourse, setEditingCourse] = useState<Course | undefined>(undefined);
|
||||
const [activeTab, setActiveTab] = useState<'courses' | 'comments'>('courses');
|
||||
const [allComments, setAllComments] = useState<Array<{ comment: Comment; courseTitle: string }>>([]);
|
||||
const [commentFilter, setCommentFilter] = useState<'all' | 'unanswered' | 'answered'>('all');
|
||||
const [replyingTo, setReplyingTo] = useState<string | null>(null);
|
||||
const [replyText, setReplyText] = useState('');
|
||||
const [sendingReply, setSendingReply] = useState(false);
|
||||
@@ -441,6 +442,11 @@ export const ManageCourses: React.FC = () => {
|
||||
};
|
||||
|
||||
const published = useMemo(() => courses.filter((course) => course.status === 'published').length, [courses]);
|
||||
const visibleComments = useMemo(() => allComments.filter(({ comment }) => {
|
||||
if (commentFilter === 'unanswered') return !comment.reply;
|
||||
if (commentFilter === 'answered') return Boolean(comment.reply);
|
||||
return true;
|
||||
}), [allComments, commentFilter]);
|
||||
|
||||
const listDialogs = <>
|
||||
<ConfirmDialog open={Boolean(courseDeleteTarget)} title="Excluir curso" message={courseDeleteTarget ? `Excluir “${courseDeleteTarget.title}”? O curso será arquivado e removido da listagem.` : ''} confirmLabel="Excluir curso" onCancel={() => setCourseDeleteTarget(null)} onConfirm={() => void performDeleteCourse()} />
|
||||
@@ -454,7 +460,7 @@ export const ManageCourses: React.FC = () => {
|
||||
<div className="m-stats num"><div><b>{published}</b><small>Publicados</small></div><div><b>{courses.length - published}</b><small>Rascunhos</small></div><div><b>{analytics?.learners ?? 0}</b><small>Alunos</small></div><div><b>{analytics?.unansweredComments ?? 0}</b><small>Sem resposta</small></div></div>
|
||||
<div className="m-seg" role="tablist"><button type="button" role="tab" aria-selected={activeTab === 'courses'} onClick={() => setActiveTab('courses')}>Cursos</button><button type="button" role="tab" aria-selected={activeTab === 'comments'} onClick={() => setActiveTab('comments')}>Discussões</button></div>
|
||||
{activeTab === 'courses' ? <section className="m-group"><div className="m-list">{courses.map((course) => <div className="m-row" key={course.id}><Thumb course={course} className="m-th" /><button className="m-rt" type="button" onClick={() => openCourse(course)}><b>{course.title}</b><small>{course.status === 'published' ? 'Publicado' : 'Rascunho'} · {course.lessons.length} aulas{course.learners ? ` · ${course.learners} alunos` : ''}</small></button><button className="m-icb" type="button" onClick={() => void duplicate(course)} aria-label={`Duplicar ${course.title}`}><CopyIcon className="ph" /></button><button className="m-icb" type="button" onClick={() => setCourseDeleteTarget(course)} aria-label={`Excluir ${course.title}`}><TrashIcon className="ph" /></button></div>)}</div>{!loading && !courses.length && <p className="m-empty">Nenhum curso ainda.</p>}</section>
|
||||
: <section className="m-group"><div className="m-list multi">{allComments.map(({ comment, courseTitle }) => <div className="m-row" key={comment.id}><span className="m-rt"><b>{comment.text}</b><small>{comment.user} · {courseTitle} · {comment.date}</small>{comment.reply ? <small>Professor respondeu: {comment.reply}</small> : replyingTo === comment.id ? <span className="m-reply"><input value={replyText} onChange={(event) => setReplyText(event.target.value)} placeholder="Escrever resposta" /><button className="link" type="button" disabled={sendingReply} onClick={() => void sendReply(comment.id)}>Enviar</button></span> : <button className="link" type="button" onClick={() => { setReplyingTo(comment.id); setReplyText(''); }}>Responder</button>}<button className="link bad-text" type="button" onClick={() => setCommentDeleteTarget(comment)}>Remover</button></span></div>)}</div>{!loading && !allComments.length && <p className="m-empty">Nenhuma discussão ainda.</p>}</section>}
|
||||
: <><div className="m-chips" role="group" aria-label="Filtrar discussões">{([['all', 'Todas'], ['unanswered', 'Sem resposta'], ['answered', 'Respondidas']] as const).map(([key, label]) => <button key={key} type="button" aria-pressed={commentFilter === key} onClick={() => setCommentFilter(key)}>{label}</button>)}</div><section className="m-group"><div className="m-list multi">{visibleComments.map(({ comment, courseTitle }) => <div className="m-row" key={comment.id}><span className="m-rt"><b>{comment.text}</b><small>{comment.user} · {courseTitle} · {comment.date}</small>{comment.reply ? <small>Professor respondeu: {comment.reply}</small> : replyingTo === comment.id ? <span className="m-reply"><input value={replyText} onChange={(event) => setReplyText(event.target.value)} placeholder="Escrever resposta" /><button className="link" type="button" disabled={sendingReply} onClick={() => void sendReply(comment.id)}>Enviar</button></span> : <button className="link" type="button" onClick={() => { setReplyingTo(comment.id); setReplyText(''); }}>Responder</button>}<button className="link bad-text" type="button" onClick={() => setCommentDeleteTarget(comment)}>Remover</button></span></div>)}</div>{!loading && !visibleComments.length && <p className="m-empty">Nenhuma discussão encontrada.</p>}</section></>}
|
||||
{listDialogs}
|
||||
</main>;
|
||||
|
||||
@@ -470,9 +476,10 @@ export const ManageCourses: React.FC = () => {
|
||||
<button type="button" aria-pressed={activeTab === 'courses'} onClick={() => setActiveTab('courses')}>Cursos</button>
|
||||
<button type="button" aria-pressed={activeTab === 'comments'} onClick={() => setActiveTab('comments')}>Discussões <span className="num">{allComments.length}</span></button>
|
||||
</div>
|
||||
{activeTab === 'comments' && <div className="chips2" role="group" aria-label="Filtrar discussões">{([['all', 'Todas'], ['unanswered', 'Sem resposta'], ['answered', 'Respondidas']] as const).map(([key, label]) => <button key={key} type="button" aria-pressed={commentFilter === key} onClick={() => setCommentFilter(key)}>{label}</button>)}</div>}
|
||||
{activeTab === 'courses' ? (loading ? <div className="loading"><CircleNotchIcon className="ph spin" /></div> : courses.length ? <div className="tablewrap"><table className="t-ger"><thead><tr><th>Curso</th><th>Status</th><th>Aulas</th><th>Alunos</th><th>Atualizado</th><th></th></tr></thead><tbody>
|
||||
{courses.map((course) => <tr className="click" key={course.id} onClick={() => openCourse(course)}><td><span className="person"><Thumb course={course} /><span><b style={{ fontWeight: 500 }}>{course.title}</b><small>{course.category}</small></span></span></td><td><span className={`st ${course.status === 'published' ? 'ok' : 'mut'}`}>{course.status === 'published' ? 'Publicado' : 'Rascunho'}</span></td><td className="num">{course.lessons.length}</td><td className="num">{course.learners ?? 0}</td><td className="num">{shortDate(course.updatedAt) || '—'}</td><td className="right"><div className="acts"><button className="iconbtn" type="button" aria-label={`Editar ${course.title}`} onClick={(event) => { event.stopPropagation(); openCourse(course); }}><EditMockIcon className="ph" /></button><button className="iconbtn" type="button" aria-label={`Duplicar ${course.title}`} onClick={(event) => { event.stopPropagation(); void duplicate(course); }}><CopyIcon className="ph" /></button><button className="iconbtn" type="button" aria-label={`Excluir ${course.title}`} onClick={(event) => { event.stopPropagation(); setCourseDeleteTarget(course); }}><TrashIcon className="ph" /></button></div></td></tr>)}
|
||||
</tbody></table></div> : <p className="empty">Nenhum curso criado ainda.</p>) : allComments.length ? <div className="list">{allComments.map(({ comment, courseTitle }) => <article className="manage-comment" key={comment.id}><div><b>{comment.user}</b><small>{courseTitle} · {comment.date}</small></div><p>{comment.text}</p>{comment.reply ? <div className="reply"><small>Resposta do professor</small><p>{comment.reply}</p></div> : replyingTo === comment.id ? <div className="composer"><textarea value={replyText} onChange={(event) => setReplyText(event.target.value)} placeholder="Escreva sua resposta" /><button className="btn" type="button" disabled={sendingReply} onClick={() => void sendReply(comment.id)}>Enviar</button></div> : <button className="link" type="button" onClick={() => { setReplyingTo(comment.id); setReplyText(''); }}>Responder</button>}<button className="link bad-text" type="button" onClick={() => setCommentDeleteTarget(comment)}>Remover comentário</button></article>)}</div> : <p className="empty">Nenhuma discussão ainda.</p>}
|
||||
</tbody></table></div> : <p className="empty">Nenhum curso criado ainda.</p>) : visibleComments.length ? <div className="list">{visibleComments.map(({ comment, courseTitle }) => <article className="manage-comment" key={comment.id}><div><b>{comment.user}</b><small>{courseTitle} · {comment.date}</small></div><p>{comment.text}</p>{comment.reply ? <div className="reply"><small>Resposta do professor</small><p>{comment.reply}</p></div> : replyingTo === comment.id ? <div className="composer"><textarea value={replyText} onChange={(event) => setReplyText(event.target.value)} placeholder="Escreva sua resposta" /><button className="btn" type="button" disabled={sendingReply} onClick={() => void sendReply(comment.id)}>Enviar</button></div> : <button className="link" type="button" onClick={() => { setReplyingTo(comment.id); setReplyText(''); }}>Responder</button>}<button className="link bad-text" type="button" onClick={() => setCommentDeleteTarget(comment)}>Remover comentário</button></article>)}</div> : <p className="empty">{allComments.length ? 'Nenhuma discussão com esse filtro.' : 'Nenhuma discussão ainda.'}</p>}
|
||||
{listDialogs}
|
||||
</main>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user