Skip to content

Commit

Permalink
only refresh follow button
Browse files Browse the repository at this point in the history
  • Loading branch information
yp05327 committed Feb 1, 2024
1 parent a86df06 commit 56a477f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 61 deletions.
13 changes: 12 additions & 1 deletion routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,22 @@ func Home(ctx *context.Context) {
if ctx.Written() {
return
}
shared_user.PrepareContextForOrgProfileBigAvatar(ctx)

org := ctx.Org.Organization

ctx.Data["PageIsUserProfile"] = true
ctx.Data["Title"] = org.DisplayName()
if len(org.Description) != 0 {
desc, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Metas: map[string]string{"mode": "document"},
}, org.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return
}
ctx.Data["RenderedDescription"] = desc
}

var orderBy db.SearchOrderBy
ctx.Data["SortType"] = ctx.FormString("sort")
Expand Down
19 changes: 0 additions & 19 deletions routers/web/shared/user/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ func prepareContextForCommonProfile(ctx *context.Context) {
ctx.Data["FeedURL"] = ctx.ContextUser.HomeLink()
}

// PrepareContextForProfileBigAvatar set the context for big avatar view on the org profile page
func PrepareContextForOrgProfileBigAvatar(ctx *context.Context) {
prepareContextForCommonProfile(ctx)

ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)

if len(ctx.ContextUser.Description) != 0 {
desc, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Metas: map[string]string{"mode": "document"},
}, ctx.ContextUser.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return
}
ctx.Data["RenderedDescription"] = desc
}
}

// PrepareContextForProfileBigAvatar set the context for big avatar view on the profile page
func PrepareContextForProfileBigAvatar(ctx *context.Context) {
prepareContextForCommonProfile(ctx)
Expand Down
8 changes: 4 additions & 4 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
)

const (
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
tplOrgProfileBigAvatar base.TplName = "shared/user/org_profile_big_avatar"
tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar"
tplFollowUnfollow base.TplName = "shared/user/follow_unfollow"
)

// OwnerProfile render profile page for a user or a organization (aka, repo owner)
Expand Down Expand Up @@ -324,8 +324,8 @@ func Action(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplProfileBigAvatar)
return
} else if ctx.ContextUser.IsOrganization() {
shared_user.PrepareContextForOrgProfileBigAvatar(ctx)
ctx.HTML(http.StatusOK, tplOrgProfileBigAvatar)
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
ctx.HTML(http.StatusOK, tplFollowUnfollow)
return
}
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
Expand Down
37 changes: 36 additions & 1 deletion templates/org/home.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content organization profile">
{{template "shared/user/org_profile_big_avatar" .}}
<div class="ui container gt-df">
{{ctx.AvatarUtils.Avatar .Org 140 "org-avatar"}}
<div id="org-info">
<div class="ui header">
{{.Org.DisplayName}}
<span class="org-visibility">
{{if .Org.Visibility.IsLimited}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}</span>{{end}}
{{if .Org.Visibility.IsPrivate}}<span class="ui large basic horizontal label">{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}</span>{{end}}
</span>
</div>
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
<div class="text grey meta">
{{if .Org.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
{{if .Org.Website}}<div class="flex-text-block">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
{{if $.IsSigned}}
{{if .Org.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.Org.Email}}">{{.Org.Email}}</a></div>{{end}}
{{end}}
</div>
</div>
<div class="right menu">
{{if .EnableFeed}}
<a class="ui basic label button gt-mr-0" href="{{$.Org.HomeLink}}.rss" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">
{{svg "octicon-rss" 24}}
</a>
{{end}}
{{if .IsSigned}}
<button class="ui basic button gt-mr-0" hx-post="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
{{if $.IsFollowing}}
{{ctx.Locale.Tr "user.unfollow"}}
{{else}}
{{ctx.Locale.Tr "user.follow"}}
{{end}}
</button>
{{end}}
</div>
</div>

{{template "org/menu" .}}

Expand Down
36 changes: 0 additions & 36 deletions templates/shared/user/org_profile_big_avatar.tmpl

This file was deleted.

0 comments on commit 56a477f

Please sign in to comment.