Skip to content

Commit 80eb506

Browse files
authored
Fix followers and following tabs in profile (#10202) (#10203)
1 parent b16c555 commit 80eb506

File tree

6 files changed

+35
-87
lines changed

6 files changed

+35
-87
lines changed

routers/routes/routes.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,7 @@ func RegisterRoutes(m *macaron.Macaron) {
475475
// ***** END: Admin *****
476476

477477
m.Group("", func() {
478-
m.Group("/:username", func() {
479-
m.Get("", user.Profile)
480-
m.Get("/followers", user.Followers)
481-
m.Get("/following", user.Following)
482-
})
483-
478+
m.Get("/:username", user.Profile)
484479
m.Get("/attachments/:uuid", repo.GetAttachment)
485480
}, ignSignIn)
486481

routers/user/profile.go

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ import (
1111
"strings"
1212

1313
"code.gitea.io/gitea/models"
14-
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/context"
1615
"code.gitea.io/gitea/modules/setting"
1716
"code.gitea.io/gitea/modules/util"
1817
"code.gitea.io/gitea/routers/org"
19-
"code.gitea.io/gitea/routers/repo"
20-
)
21-
22-
const (
23-
tplFollowers base.TplName = "user/meta/followers"
2418
)
2519

2620
// GetUserByName get user by name
@@ -164,6 +158,24 @@ func Profile(ctx *context.Context) {
164158
keyword := strings.Trim(ctx.Query("q"), " ")
165159
ctx.Data["Keyword"] = keyword
166160
switch tab {
161+
case "followers":
162+
items, err := ctxUser.GetFollowers(page)
163+
if err != nil {
164+
ctx.ServerError("GetFollowers", err)
165+
return
166+
}
167+
ctx.Data["Cards"] = items
168+
169+
total = ctxUser.NumFollowers
170+
case "following":
171+
items, err := ctxUser.GetFollowing(page)
172+
if err != nil {
173+
ctx.ServerError("GetFollowing", err)
174+
return
175+
}
176+
ctx.Data["Cards"] = items
177+
178+
total = ctxUser.NumFollowing
167179
case "activity":
168180
retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
169181
RequestingUserID: requestingUserID,
@@ -229,32 +241,6 @@ func Profile(ctx *context.Context) {
229241
ctx.HTML(200, tplProfile)
230242
}
231243

232-
// Followers render user's followers page
233-
func Followers(ctx *context.Context) {
234-
u := GetUserByParams(ctx)
235-
if ctx.Written() {
236-
return
237-
}
238-
ctx.Data["Title"] = u.DisplayName()
239-
ctx.Data["CardsTitle"] = ctx.Tr("user.followers")
240-
ctx.Data["PageIsFollowers"] = true
241-
ctx.Data["Owner"] = u
242-
repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, tplFollowers)
243-
}
244-
245-
// Following render user's followering page
246-
func Following(ctx *context.Context) {
247-
u := GetUserByParams(ctx)
248-
if ctx.Written() {
249-
return
250-
}
251-
ctx.Data["Title"] = u.DisplayName()
252-
ctx.Data["CardsTitle"] = ctx.Tr("user.following")
253-
ctx.Data["PageIsFollowing"] = true
254-
ctx.Data["Owner"] = u
255-
repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, tplFollowers)
256-
}
257-
258244
// Action response for follow/unfollow user request
259245
func Action(ctx *context.Context) {
260246
u := GetUserByParams(ctx)

templates/repo/user_cards.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div class="ui container user-cards">
2+
{{if .CardsTitle}}
23
<h2 class="ui dividing header">
34
{{.CardsTitle}}
45
</h2>
6+
{{end}}
57
<ul class="list">
68
{{range .Cards}}
79
<li class="item ui segment">

templates/user/meta/followers.tmpl

Lines changed: 0 additions & 6 deletions
This file was deleted.

templates/user/meta/header.tmpl

Lines changed: 0 additions & 24 deletions
This file was deleted.

templates/user/profile.tmpl

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,6 @@
4949
{{end}}
5050
{{end}}
5151
<li><i class="octicon octicon-clock"></i> {{.i18n.Tr "user.join_on"}} {{.Owner.CreatedUnix.FormatShort}}</li>
52-
<li>
53-
<i class="octicon octicon-person"></i>
54-
<a href="{{.Owner.HomeLink}}/followers">
55-
{{.Owner.NumFollowers}} {{.i18n.Tr "user.followers"}}
56-
</a>
57-
-
58-
<a href="{{.Owner.HomeLink}}/following">
59-
{{.Owner.NumFollowing}} {{.i18n.Tr "user.following"}}
60-
</a>
61-
</li>
62-
{{/*
63-
<li>
64-
<i class="octicon octicon-star"></i>
65-
<a href="{{.Owner.HomeLink}}/stars">
66-
{{.Owner.NumStars}} {{.i18n.Tr "user.starred"}}
67-
</a>
68-
</li>
69-
*/}}
7052
{{if and .Orgs .HasOrgsVisible}}
7153
<li>
7254
<ul class="user-orgs">
@@ -95,14 +77,23 @@
9577
</div>
9678
<div class="ui eleven wide column">
9779
<div class="ui secondary stackable pointing menu">
98-
<a class='{{if and (ne .TabName "activity") (ne .TabName "stars")}}active{{end}} item' href="{{.Owner.HomeLink}}">
80+
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars")}}active{{end}} item' href="{{.Owner.HomeLink}}">
9981
<i class="octicon octicon-repo"></i> {{.i18n.Tr "user.repositories"}}
10082
</a>
10183
<a class='{{if eq .TabName "activity"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=activity">
10284
<i class="octicon octicon-rss"></i> {{.i18n.Tr "user.activity"}}
10385
</a>
10486
<a class='{{if eq .TabName "stars"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=stars">
10587
<i class="octicon octicon-star"></i> {{.i18n.Tr "user.starred"}}
88+
<div class="ui label">{{.Owner.NumStars}}</div>
89+
</a>
90+
<a class='{{if eq .TabName "following"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=following">
91+
<i class="octicon octicon-person"></i> {{.i18n.Tr "user.following"}}
92+
<div class="ui label">{{.Owner.NumFollowing}}</div>
93+
</a>
94+
<a class='{{if eq .TabName "followers"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=followers">
95+
<i class="octicon octicon-person"></i> {{.i18n.Tr "user.followers"}}
96+
<div class="ui label">{{.Owner.NumFollowers}}</div>
10697
</a>
10798
</div>
10899

@@ -126,6 +117,10 @@
126117
{{template "explore/repo_list" .}}
127118
{{template "base/paginate" .}}
128119
</div>
120+
{{else if eq .TabName "following"}}
121+
{{template "repo/user_cards" .}}
122+
{{else if eq .TabName "followers"}}
123+
{{template "repo/user_cards" .}}
129124
{{else}}
130125
{{template "explore/repo_search" .}}
131126
{{template "explore/repo_list" .}}

0 commit comments

Comments
 (0)