aboutsummaryrefslogtreecommitdiff
path: root/views/nodes.templ
blob: c9baf2e1390295993623b9f215cf4db21990903a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package views

import (
	"fmt"
	"gitrepo.ru/neonxp/gorum/models"
	"gitrepo.ru/neonxp/gorum/utils"
)

templ Node(node *models.Node, nodes []*models.Node, count int) {
	@Layout() {
		<h1>{ node.Text }</h1>
		<table>
			<thead>
				<tr>
					<th>Тема</th>
					<th>Дата</th>
					<th>Автор</th>
				</tr>
			</thead>
			<tbody>
				for _, n := range nodes {
					if n.Type == models.TopicType {
						@Topic(n)
					}
				}
				if len(nodes) == 0 {
					<tr>
						<td colspan="3">
							<strong>Тем нет</strong>
						</td>
					</tr>
				}
			</tbody>
		</table>
		if len(nodes) == 0 {
			<strong>Постов нет</strong>
		}
		for _, n := range nodes {
			if n.Type == models.PostType {
				@Post(n)
			}
		}
		if isAuthorized(ctx) {
			@NewNode(node)
		} else {
			<a href="/login">Войдите</a> чтобы ответить в тему.
		}
	}
}

templ Topic(n *models.Node) {
	<tr>
		<td>
			<a href={ templ.URL(fmt.Sprintf("/n/%d", n.ID)) }>{ n.Text }</a>
		</td>
		<td>
			{ utils.FormatDate(n.CreatedAt) }
		</td>
		<td>
			{ n.Author.Username }
		</td>
	</tr>
}

templ Post(n *models.Node) {
	<article id={ fmt.Sprintf("post%d", n.ID) }>
		<header class="post-header">
			<span>Пост</span>
			<span>
				{ n.Author.Username }
				в
				{ utils.FormatDate(n.CreatedAt) }
				<a
					href={ templ.URL(fmt.Sprintf("/n/%d#post%d", n.ParentID, n.ID)) }
				>
					#
				</a>
			</span>
		</header>
		@templ.Raw(utils.MarkdownToHTML(n.Text))
	</article>
}