Clientside delete thread button
This commit is contained in:
+7
-1
@@ -29,7 +29,13 @@ func AdminOnlyMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := r.Cookie("comfy_admin")
|
||||
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
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
+32
-1
@@ -279,7 +279,6 @@ body {
|
||||
|
||||
/* ADMIN */
|
||||
|
||||
|
||||
.admin-login-container {
|
||||
width: max-content;
|
||||
margin: auto;
|
||||
@@ -295,6 +294,38 @@ body {
|
||||
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 */
|
||||
|
||||
.container {
|
||||
|
||||
+28
-5
@@ -69,7 +69,8 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogCont
|
||||
for _, preview := range previews {
|
||||
{{ replyCount := strconv.FormatInt(int64(preview.ReplyCount), 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) }>
|
||||
<img
|
||||
loading="lazy"
|
||||
@@ -78,20 +79,42 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogCont
|
||||
preview.ThumbPath) }
|
||||
/>
|
||||
</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>
|
||||
<a href={ templ.URL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a>
|
||||
</h1>
|
||||
<p>
|
||||
@templ.Raw(util.EnrichPost(preview.Body))
|
||||
</p>
|
||||
if catalogContext.IsAdmin {
|
||||
<dialog
|
||||
id={ elThreadId + "-dialog" }
|
||||
class="admin-dialog"
|
||||
>
|
||||
<h1>{ elThreadId }</h1>
|
||||
<button
|
||||
class="link-button"
|
||||
hx-delete={ fmt.Sprintf("/admin/%s/threads/%d", catalogContext.BoardSlug, preview.ThreadId) }
|
||||
hx-swap="none"
|
||||
_="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>
|
||||
|
||||
Reference in New Issue
Block a user