summaryrefslogtreecommitdiff
path: root/srv/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'srv/src/api')
-rw-r--r--srv/src/api/render.go17
-rw-r--r--srv/src/api/tpl/index.html8
2 files changed, 22 insertions, 3 deletions
diff --git a/srv/src/api/render.go b/srv/src/api/render.go
index b2ca3c8..6359505 100644
--- a/srv/src/api/render.go
+++ b/srv/src/api/render.go
@@ -59,7 +59,7 @@ func (a *api) renderIndexHandler() http.Handler {
return
}
- posts, _, err := a.params.PostStore.Get(page, pageCount)
+ posts, hasMore, err := a.params.PostStore.WithOrderDesc().Get(page, pageCount)
if err != nil {
apiutil.InternalServerError(
rw, r, fmt.Errorf("fetching page %d of posts: %w", page, err),
@@ -68,9 +68,20 @@ func (a *api) renderIndexHandler() http.Handler {
}
tplData := struct {
- Posts []post.StoredPost
+ Posts []post.StoredPost
+ PrevPage, NextPage int
}{
- Posts: posts,
+ Posts: posts,
+ PrevPage: -1,
+ NextPage: -1,
+ }
+
+ if page > 0 {
+ tplData.PrevPage = page - 1
+ }
+
+ if hasMore {
+ tplData.NextPage = page + 1
}
if err := tpl.Execute(rw, tplData); err != nil {
diff --git a/srv/src/api/tpl/index.html b/srv/src/api/tpl/index.html
index 240df92..b71dc01 100644
--- a/srv/src/api/tpl/index.html
+++ b/srv/src/api/tpl/index.html
@@ -17,4 +17,12 @@
</ul>
{{ end }}
+{{ if ge .PrevPage 0 }}
+<a href="?p={{ .PrevPage}}">Previous</a>
+{{ end }}
+
+{{ if ge .NextPage 0 }}
+<a href="?p={{ .NextPage}}">Next</a>
+{{ end }}
+
{{ template "base.html" . }}