From 6da802744630e98d341a4b958103464de28a7152 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 27 Apr 2026 19:33:10 +0200 Subject: [PATCH] Fix inconsistent disabled styling on logged-out repo header buttons (#37406) Make the watch, star, and fork buttons in the repo header consistent for logged-out users: - Apply the same look to all three buttons (number labels included), instead of only the action button being grayed. - Clicking any of them while logged out now leads to the login page (with a redirect back) instead of being inert. - Split the per-button markup out of `header.tmpl` into a dedicated `templates/repo/header/` folder (`fork.tmpl`, `star.tmpl`, `watch.tmpl`). --------- Co-authored-by: Claude (Opus 4.7) Co-authored-by: wxiaoguang --- routers/web/repo/star.go | 2 +- routers/web/repo/watch.go | 2 +- templates/repo/header.tmpl | 53 ++----------------- templates/repo/header/fork.tmpl | 47 ++++++++++++++++ .../{star_unstar.tmpl => header/star.tmpl} | 6 +-- .../{watch_unwatch.tmpl => header/watch.tmpl} | 8 +-- 6 files changed, 59 insertions(+), 59 deletions(-) create mode 100644 templates/repo/header/fork.tmpl rename templates/repo/{star_unstar.tmpl => header/star.tmpl} (84%) rename templates/repo/{watch_unwatch.tmpl => header/watch.tmpl} (76%) diff --git a/routers/web/repo/star.go b/routers/web/repo/star.go index 8cfbfefdf14..c93c877d636 100644 --- a/routers/web/repo/star.go +++ b/routers/web/repo/star.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/gitea/services/context" ) -const tplStarUnstar templates.TplName = "repo/star_unstar" +const tplStarUnstar templates.TplName = "repo/header/star" func ActionStar(ctx *context.Context) { err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "star") diff --git a/routers/web/repo/watch.go b/routers/web/repo/watch.go index a7fbfc168be..616e1ee89c7 100644 --- a/routers/web/repo/watch.go +++ b/routers/web/repo/watch.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/gitea/services/context" ) -const tplWatchUnwatch templates.TplName = "repo/watch_unwatch" +const tplWatchUnwatch templates.TplName = "repo/header/watch" func ActionWatch(ctx *context.Context) { err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "watch") diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 9ed74d50bc0..9fbe6a9a114 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -57,59 +57,12 @@ {{svg "octicon-rss" 16}} {{end}} - {{template "repo/watch_unwatch" $}} + {{template "repo/header/watch" $}} {{if not $.DisableStars}} - {{template "repo/star_unstar" $}} + {{template "repo/header/star" $}} {{end}} {{if and (not .IsEmpty) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}} - - + {{template "repo/header/fork" $}} {{end}} {{end}} diff --git a/templates/repo/header/fork.tmpl b/templates/repo/header/fork.tmpl new file mode 100644 index 00000000000..e14851f0684 --- /dev/null +++ b/templates/repo/header/fork.tmpl @@ -0,0 +1,47 @@ +{{$canNotForkOwn := and $.IsSigned (not $.CanSignedUserFork) (not $.UserAndOrgForks)}} + +{{if $.ShowForkModal}} + +{{end}} diff --git a/templates/repo/star_unstar.tmpl b/templates/repo/header/star.tmpl similarity index 84% rename from templates/repo/star_unstar.tmpl rename to templates/repo/header/star.tmpl index 7e4c61aa286..d1762bc004e 100644 --- a/templates/repo/star_unstar.tmpl +++ b/templates/repo/header/star.tmpl @@ -1,18 +1,18 @@
{{$buttonText := ctx.Locale.Tr "repo.star"}} {{if $.IsStaringRepo}}{{$buttonText = ctx.Locale.Tr "repo.unstar"}}{{end}} - + {{CountFmt .Repository.NumStars}} diff --git a/templates/repo/watch_unwatch.tmpl b/templates/repo/header/watch.tmpl similarity index 76% rename from templates/repo/watch_unwatch.tmpl rename to templates/repo/header/watch.tmpl index 1d6daac2522..a00fd01c804 100644 --- a/templates/repo/watch_unwatch.tmpl +++ b/templates/repo/header/watch.tmpl @@ -1,19 +1,19 @@
{{$buttonText := ctx.Locale.Tr "repo.watch"}} {{if $.IsWatchingRepo}}{{$buttonText = ctx.Locale.Tr "repo.unwatch"}}{{end}} - - + + {{CountFmt .Repository.NumWatches}}