render thread catalog posts

This commit is contained in:
Dominic Ferrando
2025-04-18 01:09:49 -04:00
parent 0146a9583d
commit a8e1443f03
7 changed files with 305 additions and 62 deletions
+33 -32
View File
@@ -1,42 +1,43 @@
package views
import (
"fmt"
database "github.com/dominicf2001/comfychan/internal/database"
"github.com/dominicf2001/comfychan/web/views/shared"
"fmt"
database "github.com/dominicf2001/comfychan/internal/database"
"github.com/dominicf2001/comfychan/web/views/shared"
)
templ NewThreadForm() {
<form style="display: none;" id="newThreadForm" style="display: ;">
<div>
<table>
<tbody>
<tr class="new-thread-form-field">
<th>Subject</th>
<td><input/></td>
</tr>
<tr class="new-thread-form-field">
<th>Comment</th>
<td><textarea></textarea></td>
</tr>
</tbody>
</table>
</div>
</form>
<form style="display: none;" id="newThreadForm" style="display: ;">
<div>
<table>
<tbody>
<tr class="new-thread-form-field">
<th>Subject</th>
<td><input /></td>
</tr>
<tr class="new-thread-form-field">
<th>Comment</th>
<td><textarea></textarea></td>
</tr>
</tbody>
</table>
</div>
</form>
}
templ Board(board database.Board) {
@shared.Layout() {
<header class="board-header">
<img src="/static/img/banner-comfy.png"/>
<h1>
{ fmt.Sprintf("/%s/ - %s", board.Slug, board.Name) }
</h1>
<p>{ board.Tag }</p>
</header>
<div class="new-thread-container">
<button _="on click hide me then show #newThreadForm" id="newThreadBtn">[New Thread]</button>
@NewThreadForm()
</div>
}
@shared.Layout() {
<header class="board-header">
<img src="/static/img/banner-comfy.png" />
<h1>
{ fmt.Sprintf("/%s/ - %s", board.Slug, board.Name) }
</h1>
<p>{ board.Tag }</p>
</header>
<div class="new-thread-container">
<button _="on click hide me then show #newThreadForm" id="newThreadBtn">[New Thread]</button>
@NewThreadForm()
</div>
<div hx-get={ fmt.Sprintf("/hx/%d/posts/grid", board.Id) } hx-trigger="load" id="threadCatalog"></div>
}
}
+17
View File
@@ -0,0 +1,17 @@
package views
import "github.com/dominicf2001/comfychan/internal/database"
type ThreadGridBoxViewModel struct {
Thread database.Thread
Posts []database.Post
}
templ PostsGrid(vms []ThreadGridBoxViewModel) {
for _, vm := range vms {
<div class="thread-catalog-post">
<h1>{ vm.Thread.Subject }</h1>
<p>{ vm.Posts[0].Body }</p>
</div>
}
}
+27 -29
View File
@@ -1,33 +1,31 @@
package shared
templ Layout() {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Comfychan</title>
<script src="https://unpkg.com/hyperscript.org@0.9.14"></script>
<link rel="stylesheet" href="/static/reset.css" />
<link rel="stylesheet" href="/static/index.css" />
</head>
<body>
<div id="boardList">
<span>
[
<a href="/">index</a>
]
</span>
<span>
[
<a href="/comfy">comfy</a> /
<a href="/g">g</a>
]
</span>
</div>
{ children... }
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Comfychan</title>
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="https://unpkg.com/hyperscript.org@0.9.14"></script>
<link rel="stylesheet" href="/static/reset.css"/>
<link rel="stylesheet" href="/static/index.css"/>
</head>
<body>
<div id="boardList">
<span>
[
<a href="/">index</a>
]
</span>
<span>
[
<a href="/comfy">comfy</a> /
<a href="/g">g</a>
]
</span>
</div>
{ children... }
</body>
</html>
}