From 80eb50655a33dd7945ae2cbabf255c4138335dcf Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Sun, 9 Feb 2020 23:00:24 +0200 Subject: [PATCH] Fix followers and following tabs in profile (#10202) (#10203) --- routers/routes/routes.go | 7 +---- routers/user/profile.go | 50 +++++++++++------------------- templates/repo/user_cards.tmpl | 2 ++ templates/user/meta/followers.tmpl | 6 ---- templates/user/meta/header.tmpl | 24 -------------- templates/user/profile.tmpl | 33 +++++++++----------- 6 files changed, 35 insertions(+), 87 deletions(-) delete mode 100644 templates/user/meta/followers.tmpl delete mode 100644 templates/user/meta/header.tmpl diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 08cc52e0e..9d59ade3a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -475,12 +475,7 @@ func RegisterRoutes(m *macaron.Macaron) { // ***** END: Admin ***** m.Group("", func() { - m.Group("/:username", func() { - m.Get("", user.Profile) - m.Get("/followers", user.Followers) - m.Get("/following", user.Following) - }) - + m.Get("/:username", user.Profile) m.Get("/attachments/:uuid", repo.GetAttachment) }, ignSignIn) diff --git a/routers/user/profile.go b/routers/user/profile.go index fd29a1762..b54a68db7 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -11,16 +11,10 @@ import ( "strings" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers/org" - "code.gitea.io/gitea/routers/repo" -) - -const ( - tplFollowers base.TplName = "user/meta/followers" ) // GetUserByName get user by name @@ -164,6 +158,24 @@ func Profile(ctx *context.Context) { keyword := strings.Trim(ctx.Query("q"), " ") ctx.Data["Keyword"] = keyword switch tab { + case "followers": + items, err := ctxUser.GetFollowers(page) + if err != nil { + ctx.ServerError("GetFollowers", err) + return + } + ctx.Data["Cards"] = items + + total = ctxUser.NumFollowers + case "following": + items, err := ctxUser.GetFollowing(page) + if err != nil { + ctx.ServerError("GetFollowing", err) + return + } + ctx.Data["Cards"] = items + + total = ctxUser.NumFollowing case "activity": retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser, RequestingUserID: requestingUserID, @@ -229,32 +241,6 @@ func Profile(ctx *context.Context) { ctx.HTML(200, tplProfile) } -// Followers render user's followers page -func Followers(ctx *context.Context) { - u := GetUserByParams(ctx) - if ctx.Written() { - return - } - ctx.Data["Title"] = u.DisplayName() - ctx.Data["CardsTitle"] = ctx.Tr("user.followers") - ctx.Data["PageIsFollowers"] = true - ctx.Data["Owner"] = u - repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, tplFollowers) -} - -// Following render user's followering page -func Following(ctx *context.Context) { - u := GetUserByParams(ctx) - if ctx.Written() { - return - } - ctx.Data["Title"] = u.DisplayName() - ctx.Data["CardsTitle"] = ctx.Tr("user.following") - ctx.Data["PageIsFollowing"] = true - ctx.Data["Owner"] = u - repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, tplFollowers) -} - // Action response for follow/unfollow user request func Action(ctx *context.Context) { u := GetUserByParams(ctx) diff --git a/templates/repo/user_cards.tmpl b/templates/repo/user_cards.tmpl index 3677bab63..cd7f15a71 100644 --- a/templates/repo/user_cards.tmpl +++ b/templates/repo/user_cards.tmpl @@ -1,7 +1,9 @@
+ {{if .CardsTitle}}

{{.CardsTitle}}

+ {{end}}
@@ -126,6 +117,10 @@ {{template "explore/repo_list" .}} {{template "base/paginate" .}}
+ {{else if eq .TabName "following"}} + {{template "repo/user_cards" .}} + {{else if eq .TabName "followers"}} + {{template "repo/user_cards" .}} {{else}} {{template "explore/repo_search" .}} {{template "explore/repo_list" .}}