/
HyperTalbot
/
CollabHub
Обзор
Документация
Войти
/
HyperTalbot
/
CollabHub
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
frontend/utils/commentTree.ts
31 строка
1 KB
hypertalbot
✅ -> auth, register; 50/50 -> header, frontend(postogram)
15 ноя 2025, 11:24
15 ноя 2025, 11:24
c634329
Код
Авторство
О чём код?
// /frontend/utils/commentTree.ts import { CommentType } from '@/components/comment/Comment'; // Рекурсивная функция для построения дерева комментариев export const buildCommentTree = (comments: CommentType[], parentId: number | null = null): CommentType[] => { const tree: CommentType[] = []; comments.forEach(comment => { // ИСПРАВЛЕНИЕ: // !comment.parent_id будет true для null, undefined и 0. const isTopLevel = parentId === null && !comment.parent_id; // Проверка для ответов (остается без изменений) const isReply = parentId !== null && comment.parent_id === parentId; if (isTopLevel || isReply) { // Находим все ответы на текущий комментарий const replies = buildCommentTree(comments, comment.id); const parentDepth = parentId ? (comments.find(c => c.id === parentId)?.depth || 0) : 0; const currentDepth = parentDepth + 1; comment.depth = currentDepth; comment.replies = replies; tree.push(comment); } }); return tree; };