MCPcopy Create free account
hub / github.com/firebase/quickstart-js / addCommentElement

Function addCommentElement

database/scripts/main.ts:380–398  ·  view source on GitHub ↗

* Creates a comment element and adds it to the given postElement.

(
  postElement: HTMLElement,
  id: string | null,
  text: string,
  author: string,
)

Source from the content-addressed store, hash-verified

378 * Creates a comment element and adds it to the given postElement.
379 */
380function 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.

Callers 1

createPostElementFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected