Add pages for users

This commit is contained in:
video-prize-ranch 2022-02-02 10:22:48 -05:00
parent 5596998511
commit 41012edf9e
No known key found for this signature in database
GPG Key ID: D8EAA4C5B12A7281
4 changed files with 30 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package pages
import (
"strconv"
"sync"
"codeberg.org/video-prize-ranch/rimgo/api"
@ -14,6 +15,16 @@ func HandleUser(c *fiber.Ctx) error {
c.Set("Cache-Control", "public,max-age=604800")
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'unsafe-inline' 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
page := "0"
if c.Query("page") != "" {
page = c.Query("page")
}
pageNumber, err := strconv.Atoi(c.Query("page"))
if err != nil {
pageNumber = 0
}
wg := sync.WaitGroup{}
wg.Add(2)
user, err := types.User{}, error(nil)
@ -28,7 +39,7 @@ func HandleUser(c *fiber.Ctx) error {
submissions, err := []types.Submission{}, error(nil)
go func() {
defer wg.Done()
submissions, err = api.FetchSubmissions(c.Params("userID"), "newest", "0")
submissions, err = api.FetchSubmissions(c.Params("userID"), "newest", page)
}()
if err != nil {
return err
@ -38,5 +49,8 @@ func HandleUser(c *fiber.Ctx) error {
return c.Render("user", fiber.Map{
"user": user,
"submissions": submissions,
"page": page,
"nextPage": pageNumber + 1,
"prevPage": pageNumber - 1,
})
}

View File

@ -60,4 +60,10 @@ video:not(:fullscreen) {
.post__meta .material-icons-outlined {
font-size: 1rem;
}
.pageSelector {
display: flex;
justify-content: space-between;
margin-top: 1em;
}

View File

@ -1,7 +1,7 @@
<a href="{{Link}}">
<div class="post">
{{#equal Cover.Type "video"}}
<video fullscreen controls loop poster="/{{Cover.Id}}.webp" preload="none" width="100%" height="100%">
<video controls loop poster="/{{Cover.Id}}.webp" preload="none" width="100%" height="100%">
<source src="{{Cover.Url}}" type="video/mp4" />
</video>
{{/equal}}

View File

@ -31,6 +31,14 @@
{{> partials/post }}
{{/each}}
</div>
<div class="pageSelector">
{{#equal page "0" }}
{{else}}
<a href="{{channel.RelUrl}}?page={{prevPage}}">Previous page</a>
{{/equal}}
<a href="{{channel.RelUrl}}?page={{nextPage}}">Next page</a>
</div>
</main>
{{> partials/footer }}