Implement file upload for replies

This commit is contained in:
Dominic Ferrando
2025-04-18 15:41:29 -04:00
parent 00c8057b5b
commit a80a7a4dba
6 changed files with 188 additions and 130 deletions
+45 -41
View File
@@ -1,56 +1,60 @@
package views
import (
"fmt"
database "github.com/dominicf2001/comfychan/internal/database"
"github.com/dominicf2001/comfychan/web/views/shared"
"fmt"
"github.com/dominicf2001/comfychan/internal/database"
"github.com/dominicf2001/comfychan/web/views/shared"
)
templ NewThreadForm(board database.Board) {
<form hx-encoding="multipart/form-data" style="display: none;" id="newThreadForm" hx-swap="none" hx-post={
fmt.Sprintf("/%s/threads", board.Slug) } _="on htmx:afterRequest
<form
hx-encoding="multipart/form-data"
style="display: none;"
id="newThreadForm"
hx-swap="none"
hx-post={ fmt.Sprintf("/%s/threads", board.Slug) }
_="on htmx:afterRequest
hide me
then show #newThreadBtn
then trigger refreshThreads on body">
<table>
<tbody>
<tr class="new-post-form-field">
<th>Subject</th>
<td><input name="subject" /></td>
</tr>
<tr class="new-post-form-field">
<th>Comment</th>
<td><textarea name="body" required></textarea></td>
</tr>
<tr class="new-post-form-field">
<th>File</th>
<td><input name="file" type="file" required /></td>
</tr>
</tbody>
</table>
<button type="submit">Submit</button>
</form>
then trigger refreshThreads on body"
>
<table>
<tbody>
<tr class="new-post-form-field">
<th>Subject</th>
<td><input name="subject"/></td>
</tr>
<tr class="new-post-form-field">
<th>Comment</th>
<td><textarea name="body" required></textarea></td>
</tr>
<tr class="new-post-form-field">
<th>File</th>
<td><input name="file" type="file" required/></td>
</tr>
</tbody>
</table>
<button type="submit">Submit</button>
</form>
}
templ BoardHeader(board database.Board) {
<header class="board-header">
<img src={ fmt.Sprintf("/static/img/banners/%s.png", board.Slug) } />
<h1>
{ fmt.Sprintf("/%s/ - %s", board.Slug, board.Name) }
</h1>
<p>{ board.Tag }</p>
</header>
<header class="board-header">
<img src={ fmt.Sprintf("/static/img/banners/%s.png", board.Slug) }/>
<h1>
{ fmt.Sprintf("/%s/ - %s", board.Slug, board.Name) }
</h1>
<p>{ board.Tag }</p>
</header>
}
templ Board(board database.Board) {
@shared.Layout() {
@BoardHeader(board)
<div class="new-post-container">
<button _="on click
hide me
then show #newThreadForm" id="newThreadBtn">[New Thread]</button>
@NewThreadForm(board)
</div>
<div hx-get={ fmt.Sprintf("/hx/%s/catalog", board.Slug) } hx-trigger="load, refreshThreads from:body"></div>
}
@shared.Layout() {
@BoardHeader(board)
<div class="new-post-container">
<button _="on click hide me then show #newThreadForm" id="newThreadBtn">[New Thread]</button>
@NewThreadForm(board)
</div>
<div hx-get={ fmt.Sprintf("/hx/%s/catalog", board.Slug) } hx-trigger="load, refreshThreads from:body"></div>
}
}