diff --git a/internal/web/admin.go b/internal/web/admin.go index e086a16..394fd16 100644 --- a/internal/web/admin.go +++ b/internal/web/admin.go @@ -52,7 +52,7 @@ func adminUsers(ctx echo.Context) error { return errorRes(500, "Cannot get users", err) } - if err = paginate(ctx, data, pageInt, 10, "data", "admin/users"); err != nil { + if err = paginate(ctx, data, pageInt, 10, "data", "admin/users", 1); err != nil { return errorRes(404, "Page not found", nil) } @@ -70,7 +70,7 @@ func adminGists(ctx echo.Context) error { return errorRes(500, "Cannot get gists", err) } - if err = paginate(ctx, data, pageInt, 10, "data", "admin/gists"); err != nil { + if err = paginate(ctx, data, pageInt, 10, "data", "admin/gists", 1); err != nil { return errorRes(404, "Page not found", nil) } diff --git a/internal/web/gist.go b/internal/web/gist.go index bf58406..9a18d56 100644 --- a/internal/web/gist.go +++ b/internal/web/gist.go @@ -113,7 +113,7 @@ func allGists(ctx echo.Context) error { return errorRes(500, "Error fetching gists", err) } - if err = paginate(ctx, gists, pageInt, 10, "gists", fromUser, "&sort="+sort+"&order="+order); err != nil { + if err = paginate(ctx, gists, pageInt, 10, "gists", fromUser, 2, "&sort="+sort+"&order="+order); err != nil { return errorRes(404, "Page not found", nil) } @@ -207,7 +207,7 @@ func revisions(ctx echo.Context) error { } } - if err := paginate(ctx, commits, pageInt, 10, "commits", userName+"/"+gistName+"/revisions"); err != nil { + if err := paginate(ctx, commits, pageInt, 10, "commits", userName+"/"+gistName+"/revisions", 2); err != nil { return errorRes(404, "Page not found", nil) } @@ -562,7 +562,7 @@ func likes(ctx echo.Context) error { return errorRes(500, "Error getting users who liked this gist", err) } - if err = paginate(ctx, likers, pageInt, 30, "likers", gist.User.Username+"/"+gist.Uuid+"/likes"); err != nil { + if err = paginate(ctx, likers, pageInt, 30, "likers", gist.User.Username+"/"+gist.Uuid+"/likes", 1); err != nil { return errorRes(404, "Page not found", nil) } @@ -586,7 +586,7 @@ func forks(ctx echo.Context) error { return errorRes(500, "Error getting users who liked this gist", err) } - if err = paginate(ctx, forks, pageInt, 30, "forks", gist.User.Username+"/"+gist.Uuid+"/forks"); err != nil { + if err = paginate(ctx, forks, pageInt, 30, "forks", gist.User.Username+"/"+gist.Uuid+"/forks", 2); err != nil { return errorRes(404, "Page not found", nil) } diff --git a/internal/web/util.go b/internal/web/util.go index 6228691..baee85d 100644 --- a/internal/web/util.go +++ b/internal/web/util.go @@ -171,7 +171,7 @@ func getPage(ctx echo.Context) int { return pageInt } -func paginate[T any](ctx echo.Context, data []*T, pageInt int, perPage int, templateDataName string, urlPage string, urlParams ...string) error { +func paginate[T any](ctx echo.Context, data []*T, pageInt int, perPage int, templateDataName string, urlPage string, labels int, urlParams ...string) error { lenData := len(data) if lenData == 0 && pageInt != 1 { return errors.New("page not found") @@ -191,6 +191,15 @@ func paginate[T any](ctx echo.Context, data []*T, pageInt int, perPage int, temp setData(ctx, "urlParams", template.URL(urlParams[0])) } + switch labels { + case 1: + setData(ctx, "prevLabel", "Previous") + setData(ctx, "nextLabel", "Next") + case 2: + setData(ctx, "prevLabel", "Newer") + setData(ctx, "nextLabel", "Older") + } + setData(ctx, "urlPage", urlPage) setData(ctx, templateDataName, data) return nil diff --git a/templates/base/pagination.html b/templates/base/pagination.html index fa10302..063fca1 100644 --- a/templates/base/pagination.html +++ b/templates/base/pagination.html @@ -6,22 +6,22 @@ - Newer + {{ .prevLabel }} {{ else }} - Newer + {{ .prevLabel }} {{ end }} {{ if .nextPage }} - Older + {{ .nextLabel }} {{ else }} - Older + {{ .nextLabel }} diff --git a/templates/pages/likes.html b/templates/pages/likes.html index 74b6980..8fd674e 100644 --- a/templates/pages/likes.html +++ b/templates/pages/likes.html @@ -14,6 +14,9 @@ {{ end }} +
+ {{ template "pagination" . }} +
{{ else }}