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

Function createPostElement

database/scripts/main.ts:175–327  ·  view source on GitHub ↗

* Creates a post element.

(
  postId: string,
  title: string,
  text: string,
  author?: string,
  authorId?: string,
  authorPic?: string,
)

Source from the content-addressed store, hash-verified

173 * Creates a post element.
174 */
175function createPostElement(
176 postId: string,
177 title: string,
178 text: string,
179 author?: string,
180 authorId?: string,
181 authorPic?: string,
182) {
183 const uid = auth.currentUser!.uid;
184
185 const html =
186 '<div class="post post-' +
187 postId +
188 ' mdl-cell mdl-cell--12-col ' +
189 'mdl-cell--6-col-tablet mdl-cell--4-col-desktop mdl-grid mdl-grid--no-spacing">' +
190 '<div class="mdl-card mdl-shadow--2dp">' +
191 '<div class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white">' +
192 '<h4 class="mdl-card__title-text"></h4>' +
193 '</div>' +
194 '<div class="header">' +
195 '<div>' +
196 '<div class="avatar"></div>' +
197 '<div class="username mdl-color-text--black"></div>' +
198 '</div>' +
199 '</div>' +
200 '<span class="star">' +
201 '<div class="not-starred material-icons">star_border</div>' +
202 '<div class="starred material-icons">star</div>' +
203 '<div class="star-count">0</div>' +
204 '</span>' +
205 '<div class="text"></div>' +
206 '<div class="comments-container"></div>' +
207 '<form class="add-comment" action="#">' +
208 '<div class="mdl-textfield mdl-js-textfield">' +
209 '<input class="mdl-textfield__input new-comment" type="text">' +
210 '<label class="mdl-textfield__label">Comment...</label>' +
211 '</div>' +
212 '</form>' +
213 '</div>' +
214 '</div>';
215
216 // Create the DOM element from the HTML.
217 const div = document.createElement('div');
218 div.innerHTML = html;
219 const postElement = div.firstChild as HTMLElement;
220 if (window.componentHandler) {
221 window.componentHandler.upgradeElements(
222 postElement.getElementsByClassName('mdl-textfield')[0],
223 );
224 }
225
226 const addCommentForm = postElement.getElementsByClassName(
227 'add-comment',
228 )[0] as HTMLFormElement;
229 const commentInput = postElement.getElementsByClassName(
230 'new-comment',
231 )[0] as HTMLInputElement;
232 const star = postElement.getElementsByClassName(

Callers 1

fetchPostsFunction · 0.85

Calls 6

addCommentElementFunction · 0.85
setCommentValuesFunction · 0.85
deleteCommentFunction · 0.85
updateStarCountFunction · 0.85
createNewCommentFunction · 0.85

Tested by

no test coverage detected