Skip to content

Commit

Permalink
comment replies should be working now
Browse files Browse the repository at this point in the history
  • Loading branch information
traceypooh committed Jan 26, 2025
1 parent 8d210d7 commit 1dccb4c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/sitemap
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function comments() {
OUT=$DIR/index.json
rm -f $OUT
jq -rs '. | map(.)' $DIR/*.json \
| jq '.[] | del(.replyThread) | with_entries(if .key == "_id" then .key = "id" else . end)' \
| jq '.[] | del(.replyThread) | del(.replyName) | with_entries(if .key == "_id" then .key = "id" else . end)' \
| jq -s 'flatten(1)' \
> $OUT
done
Expand Down
9 changes: 3 additions & 6 deletions js/blogtini.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,21 +657,18 @@ function create_comment_form(entryId, comments) {

globalThis.cfg = cfg // xxx

const xxx = '' // reply stuff
return `
<div class="post">
<div>
<h2 id="say-something">Say Something (* THIS IS NOT WORKING YET *)</h2>
<h2 id="say-something">Say Something</h2>
<form id="comment-form" class="new-comment" method="POST">
<h3 class="reply-notice hidden">
<span class="reply-name"></span>
<a class="reply-close-btn button"><i class="fas fa-times"></i></a>
</h3>
<input type="hidden" name="options[entryId]" value="${entryId}">
<input type="hidden" name="fields[replyThread]" value="${xxx}">
<input type="hidden" name="fields[replyID]" value="${xxx}">
<input type="hidden" name="fields[replyName]" value="${xxx}">
<input type="hidden" name="options[entryId]" value="${entryId}">
<input type="hidden" name="fields[replyID]" value="">
<input required="" name="fields[name]" type="text" placeholder="Your Name">
<input name="fields[website]" type="text" placeholder="Your Website">
Expand Down
34 changes: 15 additions & 19 deletions js/staticman.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// deno-lint-ignore-file
/* eslint-disable */

// eslint-disable-next-line wrap-iife
(function() {
const form = document.querySelector('bt-post-full').shadowRoot.querySelector('.new-comment')

if (form) {
form.querySelector('#comment-form-submit').addEventListener('click', function () {
form.querySelector('#comment-form-submit').addEventListener('click', function() {
form.classList.add('loading');
form.querySelector('#comment-form-submit').classList.add('hidden'); // hide "submit"
form.querySelector('#comment-form-submitted').classList.remove('hidden'); // show "submitted"
Expand Down Expand Up @@ -90,25 +91,20 @@

// record reply target when one of the "reply" buttons is pressed
// document.querySelector('.comments-container')
document.querySelector('bt-post-full').shadowRoot.querySelector('.comments-container')
.addEventListener('click', function (evt) {
let target = evt.target;
if (target.matches('.comment-reply-btn')){
resetReplyTarget();
let cmt = target;
while (!cmt.matches('.comment')) { // find the comment containing the clicked "reply" button
cmt = cmt.parentNode;
}
// form.querySelector('input[name="fields[replyThread]"]').value = cmt.dataset.replyThread;
form.querySelector('input[name="fields[replyID]"]').value = cmt.getAttribute('id');
let replyName = cmt.querySelector('.comment-author').innerText
form.querySelector('input[name="fields[replyName]"]').value = replyName;
document.querySelector('bt-post-full').shadowRoot.querySelectorAll('bt-comment').forEach((e) => {
e.shadowRoot.querySelector('.comment-reply-btn').addEventListener('click', function (evt) {
resetReplyTarget()
let cmt = evt.currentTarget
while (!cmt.matches('.comment')) // find the comment containing the clicked "reply" button
cmt = cmt.parentNode
form.querySelector('input[name="fields[replyID]"]').value = cmt.getAttribute('id')
const replyName = cmt.querySelector('.comment-author').innerText

// display reply name
form.querySelector('.reply-notice').classList.remove('hidden');
form.querySelector('.reply-name').innerText = replyName;
}
});
form.querySelector('.reply-notice').classList.remove('hidden')
form.querySelector('.reply-name').innerText = replyName
})
})

// handle removal of reply target when '×' is pressed
form.querySelector('.reply-close-btn').addEventListener('click', resetReplyTarget);
Expand Down
2 changes: 1 addition & 1 deletion staticman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ comments:
#
# Names of the fields the form is allowed to submit. If a field that is
# not here is part of the request, an error will be thrown.
allowedFields: ["name", "email", "website", "body", "replyID", "replyName", "replyThread"]
allowedFields: ["name", "email", "website", "body", "replyID"]

# When allowedOrigins is defined, only requests sent from one of the domains
# listed will be accepted.
Expand Down

0 comments on commit 1dccb4c

Please sign in to comment.