109 lines
2.9 KiB
Templ
109 lines
2.9 KiB
Templ
package views
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/dominicf2001/comfychan/internal/database"
|
|
"github.com/dominicf2001/comfychan/internal/util"
|
|
"github.com/dominicf2001/comfychan/web/views/shared"
|
|
"strconv"
|
|
)
|
|
|
|
templ NewThreadForm(board database.Board) {
|
|
<div style="display: none;" id="newPostWarning" class="warning">
|
|
<p>Please wait until the 2 minute cooldown is finished.</p>
|
|
</div>
|
|
<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
|
|
if event.detail.xhr.status is not 429
|
|
hide me
|
|
then show #newThreadBtn
|
|
then set #newPostBody.value to ''
|
|
then set #newPostFile.value to ''
|
|
then set #newPostSubject.value to ''
|
|
then hide #newPostWarning
|
|
then trigger refreshThreads on body
|
|
else
|
|
show #newPostWarning
|
|
end"
|
|
>
|
|
<table>
|
|
<tbody>
|
|
<tr class="new-post-form-field">
|
|
<th>Subject</th>
|
|
<td><input id="newPostSubject" name="subject"/></td>
|
|
</tr>
|
|
<tr class="new-post-form-field">
|
|
<th>Comment</th>
|
|
<td><textarea id="newPostBody" name="body" required></textarea></td>
|
|
</tr>
|
|
<tr class="new-post-form-field">
|
|
<th>File</th>
|
|
<td><input id="newPostFile" 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>
|
|
}
|
|
|
|
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>
|
|
}
|
|
}
|
|
|
|
type CatalogThreadPreview struct {
|
|
Subject string
|
|
Body string
|
|
ThreadURL string
|
|
MediaPath string
|
|
ReplyCount int
|
|
IpCount int
|
|
}
|
|
|
|
templ ThreadsCatalog(previews []CatalogThreadPreview) {
|
|
<div id="catalog">
|
|
for _, preview := range previews {
|
|
{{ replyCount := strconv.FormatInt(int64(preview.ReplyCount), 10) }}
|
|
{{ ipCount := strconv.FormatInt(int64(preview.IpCount), 10) }}
|
|
<div class="catalog-preview">
|
|
<a href={ templ.URL(preview.ThreadURL) }>
|
|
<img
|
|
loading="lazy"
|
|
class="catalog-preview-img"
|
|
src={ fmt.Sprintf("/static/img/posts/thumb/%s",
|
|
preview.MediaPath) }
|
|
/>
|
|
</a>
|
|
<strong class="catalog-preview-counts">R: { replyCount } / I: { ipCount }</strong>
|
|
<h1>
|
|
<a href={ templ.URL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a>
|
|
</h1>
|
|
<p>
|
|
@templ.Raw(util.EnrichPost(preview.Body))
|
|
</p>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|