Basic file upload for thread creation

This commit is contained in:
Dominic Ferrando
2025-04-18 15:03:54 -04:00
parent 4265b8583b
commit 00c8057b5b
4 changed files with 45 additions and 15 deletions
+6 -1
View File
@@ -7,7 +7,8 @@ database "github.com/dominicf2001/comfychan/internal/database"
)
templ NewThreadForm(board database.Board) {
<form 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">
@@ -21,6 +22,10 @@ templ NewThreadForm(board database.Board) {
<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>
+3 -1
View File
@@ -13,7 +13,9 @@ templ ThreadsCatalog(previews []CatalogThreadPreview) {
<div id="catalog">
for _, preview := range previews {
<div class="catalog-preview">
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/%s", preview.MediaPath) } />
<a href={ templ.SafeURL(preview.ThreadURL) }>
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/%s", preview.MediaPath) } />
</a>
<h1><a href={ templ.SafeURL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a></h1>
<p>{ preview.Body }</p>
</div>