Skip to content

Commit

Permalink
Fix pagination issues on user profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtvl authored and techknowlogick committed Feb 24, 2023
1 parent c93cd3d commit 122f96f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func Profile(ctx *context.Context) {
page = 1
}

pagingNum := setting.UI.User.RepoPagingNum
if tab == "activity" {
pagingNum = setting.UI.FeedPagingNum
}

topicOnly := ctx.FormBool("topic")

var (
Expand Down Expand Up @@ -164,7 +169,7 @@ func Profile(ctx *context.Context) {
switch tab {
case "followers":
items, count, err := user_model.GetUserFollowers(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
PageSize: pagingNum,
Page: page,
})
if err != nil {
Expand All @@ -176,7 +181,7 @@ func Profile(ctx *context.Context) {
total = int(count)
case "following":
items, count, err := user_model.GetUserFollowing(ctx, ctx.ContextUser, ctx.Doer, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
PageSize: pagingNum,
Page: page,
})
if err != nil {
Expand All @@ -187,15 +192,16 @@ func Profile(ctx *context.Context) {

total = int(count)
case "activity":
date := ctx.FormString("date")
items, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{
RequestedUser: ctx.ContextUser,
Actor: ctx.Doer,
IncludePrivate: showPrivate,
OnlyPerformedBy: true,
IncludeDeleted: false,
Date: ctx.FormString("date"),
Date: date,
ListOptions: db.ListOptions{
PageSize: setting.UI.FeedPagingNum,
PageSize: pagingNum,
Page: page,
},
})
Expand All @@ -204,13 +210,14 @@ func Profile(ctx *context.Context) {
return
}
ctx.Data["Feeds"] = items
ctx.Data["Date"] = date

total = int(count)
case "stars":
ctx.Data["PageIsProfileStarList"] = true
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
Expand Down Expand Up @@ -242,7 +249,7 @@ func Profile(ctx *context.Context) {
case "watching":
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
Expand All @@ -264,7 +271,7 @@ func Profile(ctx *context.Context) {
default:
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
PageSize: pagingNum,
Page: page,
},
Actor: ctx.Doer,
Expand All @@ -287,12 +294,15 @@ func Profile(ctx *context.Context) {
ctx.Data["Repos"] = repos
ctx.Data["Total"] = total

pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
pager := context.NewPagination(total, pagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "tab", "TabName")
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
pager.AddParam(ctx, "language", "Language")
}
if tab == "activity" {
pager.AddParam(ctx, "date", "Date")
}
ctx.Data["Page"] = pager
ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
Expand Down

0 comments on commit 122f96f

Please sign in to comment.