Skip to content

Commit 62aa5e2

Browse files
authored
Refactor star/watch button (#29576)
1. Use "star/unstart", but not `{{if}}un{{}}star{{}}` (the same to "watch/unwatch") 2. Use "not-mobile" for hiding the elements on mobile
1 parent dae7f1e commit 62aa5e2

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

templates/repo/star_unstar.tmpl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star">
1+
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}unstar{{else}}star{{end}}">
22
<div class="ui labeled button" {{if not $.IsSigned}}data-tooltip-content="{{ctx.Locale.Tr "repo.star_guest_user"}}"{{end}}>
3-
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}>
4-
{{if $.IsStaringRepo}}
5-
{{svg "octicon-star-fill"}}<span class="text">{{ctx.Locale.Tr "repo.unstar"}}</span>
6-
{{else}}
7-
{{svg "octicon-star"}}<span class="text">{{ctx.Locale.Tr "repo.star"}}</span>
8-
{{end}}
3+
{{$buttonText := ctx.Locale.Tr "repo.star"}}
4+
{{if $.IsStaringRepo}}{{$buttonText = ctx.Locale.Tr "repo.unstar"}}{{end}}
5+
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}} aria-label="{{$buttonText}}">
6+
{{if $.IsStaringRepo}}{{svg "octicon-star-fill"}}{{else}}{{svg "octicon-star"}}{{end}}
7+
<span class="not-mobile" aria-hidden="true">{{$buttonText}}</span>
98
</button>
109
<a hx-boost="false" class="ui basic label" href="{{$.RepoLink}}/stars">
1110
{{CountFmt .Repository.NumStars}}

templates/repo/watch_unwatch.tmpl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsWatchingRepo}}un{{end}}watch">
1+
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsWatchingRepo}}unwatch{{else}}watch{{end}}">
22
<div class="ui labeled button" {{if not $.IsSigned}}data-tooltip-content="{{ctx.Locale.Tr "repo.watch_guest_user"}}"{{end}}>
3-
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}>
4-
{{if $.IsWatchingRepo}}
5-
{{svg "octicon-eye-closed" 16}}<span class="text">{{ctx.Locale.Tr "repo.unwatch"}}</span>
6-
{{else}}
7-
{{svg "octicon-eye"}}<span class="text">{{ctx.Locale.Tr "repo.watch"}}</span>
8-
{{end}}
3+
{{$buttonText := ctx.Locale.Tr "repo.watch"}}
4+
{{if $.IsWatchingRepo}}{{$buttonText = ctx.Locale.Tr "repo.unwatch"}}{{end}}
5+
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}} aria-label="{{$buttonText}}">
6+
{{if $.IsWatchingRepo}}{{svg "octicon-eye-closed"}}{{else}}{{svg "octicon-eye"}}{{end}}
7+
<span class="not-mobile" aria-hidden="true">{{$buttonText}}</span>
98
</button>
109
<a hx-boost="false" class="ui basic label" href="{{.RepoLink}}/watchers">
1110
{{CountFmt .Repository.NumWatches}}

web_src/css/repo/header.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@
8989
.repo-header .flex-item {
9090
flex-grow: 1;
9191
}
92-
.repo-buttons .ui.labeled.button .text {
93-
display: none;
94-
}
9592
.repo-header .flex-item-trailing .label {
9693
display: none;
9794
}

0 commit comments

Comments
 (0)