]> Untitled Git - lemmy-ui.git/blob - src/shared/utils/app/search-comment-tree.ts
fix: Fix badge alignment and break out into component
[lemmy-ui.git] / src / shared / utils / app / search-comment-tree.ts
1 import { CommentNodeI } from "../../interfaces";
2
3 export default function searchCommentTree(
4   tree: CommentNodeI[],
5   id: number
6 ): CommentNodeI | undefined {
7   for (const node of tree) {
8     if (node.comment_view.comment.id === id) {
9       return node;
10     }
11
12     for (const child of node.children) {
13       const res = searchCommentTree([child], id);
14
15       if (res) {
16         return res;
17       }
18     }
19   }
20   return undefined;
21 }