| 2 | import { NOT_INITIALIZED_ERROR } from '../constants' |
| 3 | |
| 4 | function renderHeader({ meta, user, reactions }, instance) { |
| 5 | const container = document.createElement('div') |
| 6 | container.lang = "en-US" |
| 7 | container.className = 'gitment-container gitment-header-container' |
| 8 | |
| 9 | const likeButton = document.createElement('span') |
| 10 | const likedReaction = reactions.find(reaction => ( |
| 11 | reaction.content === 'heart' && reaction.user.login === user.login |
| 12 | )) |
| 13 | likeButton.className = 'gitment-header-like-btn' |
| 14 | likeButton.innerHTML = ` |
| 15 | ${heartIcon} |
| 16 | ${ likedReaction |
| 17 | ? 'Unlike' |
| 18 | : 'Like' |
| 19 | } |
| 20 | ${ meta.reactions && meta.reactions.heart |
| 21 | ? ` • <strong>${meta.reactions.heart}</strong> Liked` |
| 22 | : '' |
| 23 | } |
| 24 | ` |
| 25 | |
| 26 | if (likedReaction) { |
| 27 | likeButton.classList.add('liked') |
| 28 | likeButton.onclick = () => instance.unlike() |
| 29 | } else { |
| 30 | likeButton.classList.remove('liked') |
| 31 | likeButton.onclick = () => instance.like() |
| 32 | } |
| 33 | container.appendChild(likeButton) |
| 34 | |
| 35 | const commentsCount = document.createElement('span') |
| 36 | commentsCount.innerHTML = ` |
| 37 | ${ meta.comments |
| 38 | ? ` • <strong>${meta.comments}</strong> Comments` |
| 39 | : '' |
| 40 | } |
| 41 | ` |
| 42 | container.appendChild(commentsCount) |
| 43 | |
| 44 | const issueLink = document.createElement('a') |
| 45 | issueLink.className = 'gitment-header-issue-link' |
| 46 | issueLink.href = meta.html_url |
| 47 | issueLink.target = '_blank' |
| 48 | issueLink.innerText = 'Issue Page' |
| 49 | container.appendChild(issueLink) |
| 50 | |
| 51 | return container |
| 52 | } |
| 53 | |
| 54 | function renderComments({ meta, comments, commentReactions, currentPage, user, error }, instance) { |
| 55 | const container = document.createElement('div') |