MCPcopy
hub / github.com/imsun/gitment / renderComments

Function renderComments

src/theme/default.js:54–202  ·  view source on GitHub ↗
({ meta, comments, commentReactions, currentPage, user, error }, instance)

Source from the content-addressed store, hash-verified

52}
53
54function renderComments({ meta, comments, commentReactions, currentPage, user, error }, instance) {
55 const container = document.createElement('div')
56 container.lang = "en-US"
57 container.className = 'gitment-container gitment-comments-container'
58
59 if (error) {
60 const errorBlock = document.createElement('div')
61 errorBlock.className = 'gitment-comments-error'
62
63 if (error === NOT_INITIALIZED_ERROR
64 && user.login
65 && user.login.toLowerCase() === instance.owner.toLowerCase()) {
66 const initHint = document.createElement('div')
67 const initButton = document.createElement('button')
68 initButton.className = 'gitment-comments-init-btn'
69 initButton.onclick = () => {
70 initButton.setAttribute('disabled', true)
71 instance.init()
72 .catch(e => {
73 initButton.removeAttribute('disabled')
74 alert(e)
75 })
76 }
77 initButton.innerText = 'Initialize Comments'
78 initHint.appendChild(initButton)
79 errorBlock.appendChild(initHint)
80 } else {
81 errorBlock.innerText = error
82 }
83 container.appendChild(errorBlock)
84 return container
85 } else if (comments === undefined) {
86 const loading = document.createElement('div')
87 loading.innerText = 'Loading comments...'
88 loading.className = 'gitment-comments-loading'
89 container.appendChild(loading)
90 return container
91 } else if (!comments.length) {
92 const emptyBlock = document.createElement('div')
93 emptyBlock.className = 'gitment-comments-empty'
94 emptyBlock.innerText = 'No Comment Yet'
95 container.appendChild(emptyBlock)
96 return container
97 }
98
99 const commentsList = document.createElement('ul')
100 commentsList.className = 'gitment-comments-list'
101
102 comments.forEach(comment => {
103 const createDate = new Date(comment.created_at)
104 const updateDate = new Date(comment.updated_at)
105 const commentItem = document.createElement('li')
106 commentItem.className = 'gitment-comment'
107 commentItem.innerHTML = `
108 <a class="gitment-comment-avatar" href="${comment.user.html_url}" target="_blank">
109 <img class="gitment-comment-avatar-img" src="${comment.user.avatar_url}"/>
110 </a>
111 <div class="gitment-comment-main">

Callers

nothing calls this directly

Calls 4

initMethod · 0.80
unlikeACommentMethod · 0.80
likeACommentMethod · 0.80
gotoMethod · 0.80

Tested by

no test coverage detected