Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/posts/_expanded.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
<% end %>

<div class="post--container <%= 'deleted-content' if post.deleted? %> grid is-nowrap">
<div class="post--container <%= 'deleted-content js-deleted-post' if post.deleted? %> grid is-nowrap">
<% if post_type.has_votes || (user_signed_in? && post.post_type.has_reactions && post.post_type.reactions.any?) %>
<%= render 'posts/votes', post: post %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<% if @post.post_type.has_answers %>
<% if num_answers > 0 %>
<h2><%= pluralize(num_answers, 'answer') %></h2>
<h2 id="answers" class="js-answers-header"><%= pluralize(num_answers, 'answer') %></h2>
<% end %>
<% if num_answers > 1 %>
<div class="button-list is-gutterless has-float-right">
Expand Down
19 changes: 7 additions & 12 deletions public/assets/community/codegolf.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@
const text = await pagePromises[i];
const doc = dom_parser.parseFromString(text.toString(), 'text/html');
const [question, ...page_answers] = doc.querySelectorAll('.post');
const non_deleted_answers = page_answers.filter((answer) => answer.querySelector('.deleted-content') === null);
const non_deleted_answers = page_answers.filter((answer) => answer.querySelector('.js-deleted-post') === null);

for (const answerPost of non_deleted_answers) {

/** @type {HTMLElement | null} */
const header = answerPost.querySelector('h1, h2, h3');
const code = header?.parentElement.querySelector(':scope > pre > code');
Expand All @@ -128,8 +127,8 @@
answerID: answerPost.id,
answerURL: answerPost.querySelector('.js-permalink').href,
page: i + 1, // +1 because pages are 1-indexed while arrays are 0-indexed
username: userlink.firstChild.data.trim(),
userid: userlink.href.match(/\d+/)[0],
username: userlink?.firstChild?.data?.trim() || 'deleted user',
userid: userlink?.href?.match(/\d+/)?.[0] || '',
full_language,
language,
variant,
Expand Down Expand Up @@ -262,14 +261,14 @@
row.href = answer.answerURL;

row.innerHTML = `
<div class="toc--badge"><span class="badge is-tag is-green">${answer.score}</span></div>
<div class="toc--badge"><span class="badge is-tag is-green">${answer.score ?? 'N/A'}</span></div>
<div class="toc--full"><p class="row-summary"><span class='username has-padding-right-1'></span></p></div>
${answer.placement === 1 ? '<div class="toc--badge"><span class="badge is-tag is-yellow"><i class="fas fa-trophy"></i></span></div>'
: (settings.showPlacements ? `<div class="toc--badge"><span class="badge is-tag">#${answer.placement}</span></div>` : '')}
<div class="toc--badge"><span class="language-badge badge is-tag is-blue"></span></div>`;

row.querySelector('.username').innerText = answer.username
row.querySelector('.language-badge').innerText = answer.full_language;
row.querySelector('.language-badge').innerText = answer.full_language ?? 'N/A';
if (answer.code) {
row.querySelector('.username').after(document.createElement('code'));
row.querySelector('code').innerText = answer.code.split('\n')[0].substring(0, 200);
Expand Down Expand Up @@ -331,9 +330,7 @@
// If x were undefined, it would be automatically sorted to the end, but not so if x.score is undefined, so this needs to be stated explicitly.
sort = (x, y) => typeof x.score === "undefined" ? 1 : x.score - y.score;

document
.querySelector(".post:first-child")
.nextElementSibling.insertAdjacentElement("afterend", embed);
document.querySelector(".js-answers-header")?.insertAdjacentElement('beforebegin', embed);

refreshBoard(sort);
} else if (
Expand All @@ -343,9 +340,7 @@
// If x were undefined, it would be automatically sorted to the end, but not so if x.score is undefined, so this needs to be stated explicitly.
sort = (x, y) => typeof x.score === "undefined" ? 1 : y.score - x.score;

document
.querySelector(".post:first-child")
.nextElementSibling.insertAdjacentElement("afterend", embed);
document.querySelector(".js-answers-header")?.insertAdjacentElement("beforebegin", embed);

refreshBoard(sort);
}
Expand Down