Add ability to delete threads. Fix thread deletion logic

This commit is contained in:
Dominic Ferrando
2025-04-23 15:47:15 -04:00
parent a28cb483fa
commit e341c5d8c9
4 changed files with 57 additions and 17 deletions
+13 -3
View File
@@ -52,13 +52,19 @@ templ Board(board database.Board, isAdmin bool) {
type CatalogThreadPreview struct {
Subject string
Body string
ThreadId int
ThreadURL string
ThumbPath string
ReplyCount int
IpCount int
}
templ ThreadsCatalog(previews []CatalogThreadPreview, isAdmin bool) {
type CatalogContext struct {
IsAdmin bool
BoardSlug string
}
templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogContext) {
<div id="catalog">
for _, preview := range previews {
{{ replyCount := strconv.FormatInt(int64(preview.ReplyCount), 10) }}
@@ -79,8 +85,12 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, isAdmin bool) {
<p>
@templ.Raw(util.EnrichPost(preview.Body))
</p>
if isAdmin {
<button>X</button>
if catalogContext.IsAdmin {
<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>
}
</div>
}