Implement cooldowns

This commit is contained in:
Dominic Ferrando
2025-04-19 21:50:19 -04:00
parent 10ab0edfc8
commit ae66403cea
7 changed files with 204 additions and 116 deletions
+16 -7
View File
@@ -8,6 +8,9 @@ import (
)
templ NewThreadForm(board database.Board) {
<div style="display: none;" id="newPostWarning" class="warning">
<p>Please wait until the 2 minute cooldown is finished.</p>
</div>
<form
hx-encoding="multipart/form-data"
style="display: none;"
@@ -15,17 +18,23 @@ templ NewThreadForm(board database.Board) {
hx-swap="none"
hx-post={ fmt.Sprintf("/%s/threads", board.Slug) }
_="on htmx:afterRequest
hide me
then show #newThreadBtn
then set #newPostBody.value to ''
then set #newPostFile.value to ''
then trigger refreshThreads on body"
if event.detail.xhr.status is not 429
hide me
then show #newThreadBtn
then set #newPostBody.value to ''
then set #newPostFile.value to ''
then set #newPostSubject.value to ''
then hide #newPostWarning
then trigger refreshThreads on body
else
show #newPostWarning
end"
>
<table>
<tbody>
<tr class="new-post-form-field">
<th>Subject</th>
<td><input name="subject"/></td>
<td><input id="newPostSubject" name="subject"/></td>
</tr>
<tr class="new-post-form-field">
<th>Comment</th>
@@ -82,7 +91,7 @@ templ ThreadsCatalog(previews []CatalogThreadPreview) {
/>
</a>
<h1>
<a href={ templ.URL(preview.ThreadURL) } class="thread-subject catalog-preview-link">{ preview.Subject }</a>
<a href={ templ.URL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a>
</h1>
<p>
@templ.Raw(util.EnrichPost(preview.Body))
+11 -3
View File
@@ -62,6 +62,9 @@ templ Thread(board database.Board, thread database.Thread, posts []database.Post
<script src="/static/thread.js" defer></script>
@BoardHeader(board)
<div class="new-post-container">
<div style="display: none;" id="newPostWarning" class="warning">
<p>Please wait until the 15 second cooldown is finished.</p>
</div>
<form
hx-encoding="multipart/form-data"
id="newPostForm"
@@ -69,9 +72,14 @@ templ Thread(board database.Board, thread database.Thread, posts []database.Post
hx-post={ fmt.Sprintf("/%s/threads/%d",
board.Slug, thread.Id) }
_="on htmx:afterRequest
set #newPostBody.value to ''
then set #newPostFile.value to ''
then trigger refreshPosts on body"
if event.detail.xhr.status is not 429
set #newPostBody.value to ''
then set #newPostFile.value to ''
then hide #newPostWarning
then trigger refreshPosts on body
else
show #newPostWarning
end"
>
<table>
<tbody>