add reply button functionality

This commit is contained in:
Lera Elvoé 2025-05-24 01:07:58 +03:00
parent e7260090ac
commit ec3f144b4e
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
3 changed files with 22 additions and 4 deletions

8
js/thread.js Normal file
View File

@ -0,0 +1,8 @@
const ta = document.getElementById("post_content");
for (let button of document.querySelectorAll(".reply-button")) {
button.addEventListener("click", (e) => {
ta.value += button.value;
ta.scrollIntoView()
})
}

View File

@ -43,8 +43,10 @@
show_reply = false
end
if show_reply then
local d = post.created_at < post.edited_at and post.edited_at or post.created_at
local reply_text = ("On %s, %s said:\n%s\n\n---\n\n"):format(os.date("%c", d), post.username, post.original_markup)
%>
<button>Reply</button>
<button value="<%= reply_text %>" class="reply-button">Reply</button>
<% end %>
</span>
</div>

View File

@ -1,4 +1,11 @@
<% local is_locked = ntob(thread.is_locked) %>
<%
local is_locked = ntob(thread.is_locked)
local can_post = (not is_locked and not me:is_guest()) or me:is_mod()
-- not locked, not guest, not mod = not false and not false or false = true and true or false = true
-- locked, not guest, not mod = not true and not false or false = false and true or false = false
-- not locked, guest, not mod = not false and not true or false = true and false or false = false
-- not locked, not guest, mod = not false and not false or true = true and true and true
%>
<main>
<nav class="darkbg">
<h1 class="thread-title"><%= thread.title %></h1>
@ -16,10 +23,11 @@
<% if is_locked then -%>
<% render("views.common.infobox", {kind = constants.InfoboxKind.LOCK, msg = "This thread is locked."}) %>
<% end -%>
<% if not me:is_guest() and not is_locked then %>
<% if can_post then %>
<h1>Respond to "<%= thread.title %>"</h1>
<form method="post">
<textarea id="post_content" name="post_content" placeholder="Response body" required></textarea><br>
<textarea id="post_content" name="post_content" placeholder="Response body" rows=7 required></textarea><br>
<input type="submit" value="Post reply">
</form>
<script src="/static/js/thread.js"></script>
<% end %>