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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package main
import (
"fmt"
"net/url"
"time"
)
templ index(ps []Post, tz *time.Location) {
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tinygram</title>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<script src="/static/htmx.min.js"></script>
<link rel="preload" href="/static/style.css" as="style"/>
<link rel="stylesheet" href="/static/style.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
<link href="https://fonts.googleapis.com/css2?family=Jacquard+12&display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Grenze:wght@200;300;400&display=swap" rel="stylesheet"/>
</head>
<body>
<div id="container">
<div id="header">
<a id="uploadlink" href="/upload">
<h1>Tinygram</h1>
</a>
</div>
<div id="posts">
@posts(ps, tz)
</div>
</div>
</body>
</html>
}
templ loginPage(csrfToken string) {
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tinygram</title>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<script src="/static/htmx.min.js"></script>
<link rel="preload" href="/static/style.css" as="style"/>
<link rel="stylesheet" href="/static/style.css"/>
</head>
<body>
<form class="login" hx-encoding="multipart/form-data" hx-post="/login">
<input type="password" name="password"/>
<input type="hidden" name="_csrf" value={ csrfToken }/>
<button>
Login
</button>
</form>
</body>
</html>
}
templ uploadPage(csrfToken string) {
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tinygram</title>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<script src="/static/htmx.min.js"></script>
<link rel="preload" href="/static/style.css" as="style"/>
<link rel="stylesheet" href="/static/style.css"/>
</head>
<body>
<form
class="upload"
hx-encoding="multipart/form-data"
hx-post="/upload"
_="on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100"
>
<input type="file" name="file"/>
<input type="hidden" name="_csrf" value={ csrfToken }/>
<div>
<span>Description:</span>
<input type="text" name="description"/>
</div>
<button>
Upload
</button>
<progress id="progress" value="0" max="100"></progress>
</form>
</body>
</html>
}
templ posts(posts []Post, tz *time.Location) {
for _, post := range posts {
<div class="post">
<div class="imgcontainer">
<img src={ post.ImageID } alt={ post.ImageID }/>
</div>
<div class="summary">
<p class="description">{ post.Description }</p>
<p class="date">{ post.CreatedAt.In(tz).Format("2006-01-02 - 15:04") }</p>
</div>
</div>
}
if len(posts) > 0 {
<div
style="min-height:1px"
hx-get={ fmt.Sprintf("/posts?after=%v",
url.QueryEscape(posts[len(posts)-1].CreatedAt.Format(time.RFC3339))) }
hx-target="#posts"
hx-trigger="revealed"
hx-swap="beforeend"
></div>
}
}
|