Clientside delete thread button

This commit is contained in:
Dominic Ferrando
2025-04-23 16:42:16 -04:00
parent e341c5d8c9
commit 62a1377be0
3 changed files with 67 additions and 7 deletions
+7 -1
View File
@@ -29,7 +29,13 @@ func AdminOnlyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c, err := r.Cookie("comfy_admin") c, err := r.Cookie("comfy_admin")
if err != nil || !util.IsAdminSessionValid(c.Value) { if err != nil || !util.IsAdminSessionValid(c.Value) {
http.Redirect(w, r, "/authorize", http.StatusSeeOther) // Check if it's an HTMX request
if r.Header.Get("HX-Request") == "true" {
w.Header().Set("HX-Redirect", "/authorize")
w.WriteHeader(http.StatusOK)
} else {
http.Redirect(w, r, "/authorize", http.StatusSeeOther)
}
return return
} }
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
+32 -1
View File
@@ -279,7 +279,6 @@ body {
/* ADMIN */ /* ADMIN */
.admin-login-container { .admin-login-container {
width: max-content; width: max-content;
margin: auto; margin: auto;
@@ -295,6 +294,38 @@ body {
margin-left: auto; margin-left: auto;
} }
.admin-dialog {
border: 1px solid #B7C5D9;
background: #EDEFF7;
padding: 6px 8px;
min-width: 160px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, .25);
font-size: 12px;
color: #000;
position: fixed;
z-index: 2000;
}
.admin-dialog h1 {
margin: 0 0 8px 0;
font-size: 14px;
font-weight: bold;
color: #AF0A0F;
text-align: center;
}
.admin-dialog button {
display: block;
margin: 5px auto;
}
.admin-dialog-close-btn {
font-weight: bold;
margin-top: 20px !important;
}
/* GENERAL LAYOUT */ /* GENERAL LAYOUT */
.container { .container {
+28 -5
View File
@@ -69,7 +69,8 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogCont
for _, preview := range previews { for _, preview := range previews {
{{ replyCount := strconv.FormatInt(int64(preview.ReplyCount), 10) }} {{ replyCount := strconv.FormatInt(int64(preview.ReplyCount), 10) }}
{{ ipCount := strconv.FormatInt(int64(preview.IpCount), 10) }} {{ ipCount := strconv.FormatInt(int64(preview.IpCount), 10) }}
<div class="catalog-preview"> {{ elThreadId := fmt.Sprintf("thread-%d", preview.ThreadId) }}
<div id={ elThreadId } class="catalog-preview">
<a href={ templ.URL(preview.ThreadURL) }> <a href={ templ.URL(preview.ThreadURL) }>
<img <img
loading="lazy" loading="lazy"
@@ -78,20 +79,42 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogCont
preview.ThumbPath) } preview.ThumbPath) }
/> />
</a> </a>
<strong class="catalog-preview-counts">R: { replyCount } / I: { ipCount }</strong> <strong class="catalog-preview-counts">
R: { replyCount } / I: { ipCount }
if catalogContext.IsAdmin {
<span
id={ fmt.Sprintf("%s-admintoggle", elThreadId) }
class="link-button"
style="font-size:10px;margin-left:5px;"
_={ fmt.Sprintf(`on click call #%s-dialog.showModal()`, elThreadId) }
>
M
</span>
}
</strong>
<h1> <h1>
<a href={ templ.URL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a> <a href={ templ.URL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a>
</h1> </h1>
<p> <p>
@templ.Raw(util.EnrichPost(preview.Body)) @templ.Raw(util.EnrichPost(preview.Body))
</p> </p>
if catalogContext.IsAdmin { <dialog
id={ elThreadId + "-dialog" }
class="admin-dialog"
>
<h1>{ elThreadId }</h1>
<button <button
class="link-button"
hx-delete={ fmt.Sprintf("/admin/%s/threads/%d", catalogContext.BoardSlug, preview.ThreadId) } hx-delete={ fmt.Sprintf("/admin/%s/threads/%d", catalogContext.BoardSlug, preview.ThreadId) }
hx-swap="none" hx-swap="none"
_="on htmx:afterRequest trigger refreshPosts on body" _="on htmx:afterRequest trigger refreshPosts on body"
>X</button> hx-confirm="Are you sure you wish to delete this thread?"
} >Delete</button>
<button
class="admin-dialog-close-btn link-button"
_={ fmt.Sprintf("on click call #%s-dialog.close()", elThreadId) }
>Close</button>
</dialog>
</div> </div>
} }
</div> </div>