Skip to content

Commit

Permalink
added commented out code to reverse chronological order of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dc25 authored and Dave committed Mar 3, 2024
1 parent a2451f1 commit 5a15736
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions js/github-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ async function getComments(repo_name, comment_id, page_id, acc )
{
const comment = comments[i];
const date = new Date(comment.created_at);
acc += "<div id='gh-comment'>" +
"<img src='" + comment.user.avatar_url + "' width='24px'>" +
"<b><a href='" + comment.user.html_url + "'>" + comment.user.login + "</a></b>" +
" posted at " +
"<em>" + date.toUTCString() + "</em>" +
"<div id='gh-comment-hr'></div>" +
comment.body_html +
"</div>";
acc.push( "<div id='gh-comment'>" +
"<img src='" + comment.user.avatar_url + "' width='24px'>" +
"<b><a href='" + comment.user.html_url + "'>" + comment.user.login + "</a></b>" +
" posted at " +
"<em>" + date.toUTCString() + "</em>" +
"<div id='gh-comment-hr'></div>" +
comment.body_html +
"</div>" );
}

// Call recursively if there are more pages to display
Expand Down Expand Up @@ -51,10 +51,14 @@ function DoGithubComments(repo_name, comment_id)
try {
// post button
const url = "https://github.com/" + repo_name + "/issues/" + comment_id + "#new_comment_field";
const acc = ("<form action='" + url + "' rel='nofollow'> <input type='submit' value='Post a comment on Github' /> </form>");
const comments = await getComments(repo_name, comment_id, 1, acc);
const comments = await getComments(repo_name, comment_id, 1, []);
const commentsElement = document.getElementById('gh-comments-list');
commentsElement.innerHTML = comments;

// choose one of the next two lines to determine display order (newest or oldest first).
const commentsHtml = comments.join(''); // oldest first
// const commentsHtml = comments.reverse().join(''); // newest first

commentsElement.innerHTML = "<form action='" + url + "' rel='nofollow'> <input type='submit' value='Post a comment on Github' /> </form>" + commentsHtml;
} catch (err)
{
console.log( err.message );
Expand Down

0 comments on commit 5a15736

Please sign in to comment.