* Creates a comment element and adds it to the given postElement.
( postElement: HTMLElement, id: string | null, text: string, author: string, )
| 378 | * Creates a comment element and adds it to the given postElement. |
| 379 | */ |
| 380 | function addCommentElement( |
| 381 | postElement: HTMLElement, |
| 382 | id: string | null, |
| 383 | text: string, |
| 384 | author: string, |
| 385 | ) { |
| 386 | const comment = document.createElement('div'); |
| 387 | comment.classList.add('comment-' + id); |
| 388 | comment.innerHTML = |
| 389 | '<span class="username"></span><span class="comment"></span>'; |
| 390 | (comment.getElementsByClassName('comment')[0] as HTMLSpanElement).innerText = |
| 391 | text; |
| 392 | (comment.getElementsByClassName('username')[0] as HTMLSpanElement).innerText = |
| 393 | author || 'Anonymous'; |
| 394 | |
| 395 | const commentsContainer = |
| 396 | postElement.getElementsByClassName('comments-container')[0]; |
| 397 | commentsContainer.appendChild(comment); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Sets the comment's values in the given postElement. |