(issue: Issue, timeline: TimelineComponent)
| 91 | }); |
| 92 | |
| 93 | async function renderComments(issue: Issue, timeline: TimelineComponent) { |
| 94 | const renderPage = (page: IssueComment[]) => { |
| 95 | for (const comment of page) { |
| 96 | timeline.insertComment(comment, false); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | const pageCount = Math.ceil(issue.comments / PAGE_SIZE); |
| 101 | // always load the first page. |
| 102 | const pageLoads = [loadCommentsPage(issue.number, 1)]; |
| 103 | // if there are multiple pages, load the last page. |
| 104 | if (pageCount > 1) { |
| 105 | pageLoads.push(loadCommentsPage(issue.number, pageCount)); |
| 106 | } |
| 107 | // if the last page is small, load the penultimate page. |
| 108 | if (pageCount > 2 && issue.comments % PAGE_SIZE < 3 && |
| 109 | issue.comments % PAGE_SIZE !== 0) { |
| 110 | pageLoads.push(loadCommentsPage(issue.number, pageCount - 1)); |
| 111 | } |
| 112 | // await all loads to reduce jank. |
| 113 | const pages = await Promise.all(pageLoads); |
| 114 | for (const page of pages) { |
| 115 | renderPage(page); |
| 116 | } |
| 117 | // enable loading hidden pages. |
| 118 | let hiddenPageCount = pageCount - pageLoads.length; |
| 119 | let nextHiddenPage = 2; |
| 120 | const renderLoader = (afterPage: IssueComment[]) => { |
| 121 | if (hiddenPageCount === 0) { |
| 122 | return; |
| 123 | } |
| 124 | const load = async () => { |
| 125 | loader.setBusy(); |
| 126 | const page = await loadCommentsPage(issue.number, nextHiddenPage); |
| 127 | loader.remove(); |
| 128 | renderPage(page); |
| 129 | hiddenPageCount--; |
| 130 | nextHiddenPage++; |
| 131 | renderLoader(page); |
| 132 | }; |
| 133 | const afterComment = afterPage.pop()!; |
| 134 | const loader = timeline.insertPageLoader(afterComment, hiddenPageCount * PAGE_SIZE, load); |
| 135 | }; |
| 136 | renderLoader(pages[0]); |
| 137 | } |
| 138 | |
| 139 | export async function assertOrigin() { |
| 140 | const { origins } = await getRepoConfig(); |
no test coverage detected