Skip to content

Commit 0352b99

Browse files
GiteaBotsilverwindwxiaoguang
authored
Rewrite and restyle reaction selector and enable no-sizzle eslint rule (go-gitea#30453) (go-gitea#30473)
Backport go-gitea#30453 by @silverwind Enable `no-sizzle` lint rule, there was only one use in `initCompReactionSelector` which I have rewritten as follows: - Remove all jQuery except the necessary fomantic dropdown init - Remove the recursion, instead bind event listeners to common parent container nodes Did various tests, works with our without attachments, in diff view and in diff comments inside comment list. Additionally the style of reactions now matches between code comments and issue comments: <img width="275" alt="Screenshot 2024-04-13 at 14 58 10" src="https://github.com/go-gitea/gitea/assets/115237/9d08f188-8661-4dd9-bff4-cad6d6d09cab"> Co-authored-by: silverwind <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent dd12861 commit 0352b99

File tree

17 files changed

+133
-178
lines changed

17 files changed

+133
-178
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ rules:
317317
jquery/no-serialize: [2]
318318
jquery/no-show: [2]
319319
jquery/no-size: [2]
320-
jquery/no-sizzle: [0]
320+
jquery/no-sizzle: [2]
321321
jquery/no-slide: [0]
322322
jquery/no-submit: [0]
323323
jquery/no-text: [0]
@@ -469,7 +469,7 @@ rules:
469469
no-jquery/no-selector-prop: [2]
470470
no-jquery/no-serialize: [2]
471471
no-jquery/no-size: [2]
472-
no-jquery/no-sizzle: [0]
472+
no-jquery/no-sizzle: [2]
473473
no-jquery/no-slide: [2]
474474
no-jquery/no-sub: [2]
475475
no-jquery/no-support: [2]

routers/web/repo/issue.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,6 @@ func ChangeIssueReaction(ctx *context.Context) {
33183318
}
33193319

33203320
html, err := ctx.RenderToHTML(tplReactions, map[string]any{
3321-
"ctxData": ctx.Data,
33223321
"ActionURL": fmt.Sprintf("%s/issues/%d/reactions", ctx.Repo.RepoLink, issue.Index),
33233322
"Reactions": issue.Reactions.GroupByType(),
33243323
})
@@ -3425,7 +3424,6 @@ func ChangeCommentReaction(ctx *context.Context) {
34253424
}
34263425

34273426
html, err := ctx.RenderToHTML(tplReactions, map[string]any{
3428-
"ctxData": ctx.Data,
34293427
"ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
34303428
"Reactions": comment.Reactions.GroupByType(),
34313429
})

services/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
102102
tmplCtx := NewTemplateContext(ctx)
103103
tmplCtx["Locale"] = ctx.Base.Locale
104104
tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx)
105+
tmplCtx["RootData"] = ctx.Data
105106
return tmplCtx
106107
}
107108

templates/repo/diff/comments.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</div>
4949
{{end}}
5050
{{end}}
51-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $.root "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
51+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
5252
{{template "repo/issue/view_content/context_menu" dict "ctxData" $.root "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
5353
</div>
5454
</div>
@@ -68,7 +68,7 @@
6868
</div>
6969
{{$reactions := .Reactions.GroupByType}}
7070
{{if $reactions}}
71-
{{template "repo/issue/view_content/reactions" dict "ctxData" $.root "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions}}
71+
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions}}
7272
{{end}}
7373
</div>
7474
</div>

templates/repo/issue/view_content.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<div class="comment-header-right actions tw-flex tw-items-center">
4747
{{template "repo/issue/view_content/show_role" dict "ShowRole" .Issue.ShowRole "IgnorePoster" true}}
4848
{{if not $.Repository.IsArchived}}
49-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}}
49+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}}
5050
{{end}}
5151
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" .Issue "delete" false "issue" true "diff" false "IsCommentPoster" $.IsIssuePoster}}
5252
</div>
@@ -67,7 +67,7 @@
6767
</div>
6868
{{$reactions := .Issue.Reactions.GroupByType}}
6969
{{if $reactions}}
70-
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions}}
70+
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions}}
7171
{{end}}
7272
</div>
7373
</div>

templates/repo/issue/view_content/add_reaction.tmpl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
{{if .ctxData.IsSigned}}
1+
{{if ctx.RootData.IsSigned}}
22
<div class="item action ui dropdown jump pointing top right select-reaction" data-action-url="{{.ActionURL}}">
3-
<a class="add-reaction muted">
4-
{{svg "octicon-smiley"}}
5-
</a>
6-
<div class="menu reactions-menu">
3+
<a class="muted">{{svg "octicon-smiley"}}</a>
4+
<div class="menu">
75
{{range $value := AllowedReactions}}
8-
<a class="item reaction" data-tooltip-content="{{$value}}" aria-label="{{$value}}" data-reaction-content="{{$value}}">{{ReactionToEmoji $value}}</a>
6+
<a class="item emoji comment-reaction-button" data-tooltip-content="{{$value}}" aria-label="{{$value}}" data-reaction-content="{{$value}}">{{ReactionToEmoji $value}}</a>
97
{{end}}
108
</div>
119
</div>

templates/repo/issue/view_content/comments.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div class="comment-header-right actions tw-flex tw-items-center">
5454
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
5555
{{if not $.Repository.IsArchived}}
56-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
56+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
5757
{{end}}
5858
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
5959
</div>
@@ -74,7 +74,7 @@
7474
</div>
7575
{{$reactions := .Reactions.GroupByType}}
7676
{{if $reactions}}
77-
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
77+
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
7878
{{end}}
7979
</div>
8080
</div>
@@ -427,7 +427,7 @@
427427
<div class="comment-header-right actions tw-flex tw-items-center">
428428
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
429429
{{if not $.Repository.IsArchived}}
430-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
430+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
431431
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" false "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
432432
{{end}}
433433
</div>
@@ -448,7 +448,7 @@
448448
</div>
449449
{{$reactions := .Reactions.GroupByType}}
450450
{{if $reactions}}
451-
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
451+
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
452452
{{end}}
453453
</div>
454454
</div>

templates/repo/issue/view_content/conversation.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
<div class="ui comments tw-mb-0">
5656
{{range .comments}}
5757
{{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}}
58-
<div class="comment code-comment tw-pb-4" id="{{.HashTag}}">
59-
<div class="content">
58+
<div class="comment code-comment" id="{{.HashTag}}">
59+
<div class="content comment-container">
6060
<div class="header comment-header">
6161
<div class="comment-header-left tw-flex tw-items-center">
6262
{{if not .OriginalAuthor}}
@@ -82,7 +82,7 @@
8282
<div class="comment-header-right actions tw-flex tw-items-center">
8383
{{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}}
8484
{{if not $.Repository.IsArchived}}
85-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
85+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}}
8686
{{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
8787
{{end}}
8888
</div>
@@ -103,7 +103,7 @@
103103
</div>
104104
{{$reactions := .Reactions.GroupByType}}
105105
{{if $reactions}}
106-
{{template "repo/issue/view_content/reactions" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
106+
{{template "repo/issue/view_content/reactions" dict "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions}}
107107
{{end}}
108108
</div>
109109
</div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<div class="ui attached segment reactions" data-action-url="{{$.ActionURL}}">
1+
<div class="bottom-reactions" data-action-url="{{$.ActionURL}}">
22
{{range $key, $value := .Reactions}}
3-
{{$hasReacted := $value.HasUser $.ctxData.SignedUserID}}
4-
<a role="button" class="ui label basic{{if $hasReacted}} primary{{end}}{{if not $.ctxData.IsSigned}} disabled{{end}} comment-reaction-button"
3+
{{$hasReacted := $value.HasUser ctx.RootData.SignedUserID}}
4+
<a role="button" class="ui label basic{{if $hasReacted}} primary{{end}}{{if not ctx.RootData.IsSigned}} disabled{{end}} comment-reaction-button"
55
data-tooltip-content
66
title="{{$value.GetFirstUsers}}{{if gt ($value.GetMoreUserCount) 0}} {{ctx.Locale.Tr "repo.reactions_more" $value.GetMoreUserCount}}{{end}}"
77
aria-label="{{$value.GetFirstUsers}}{{if gt ($value.GetMoreUserCount) 0}} {{ctx.Locale.Tr "repo.reactions_more" $value.GetMoreUserCount}}{{end}}"
@@ -12,6 +12,6 @@
1212
</a>
1313
{{end}}
1414
{{if AllowedReactions}}
15-
{{template "repo/issue/view_content/add_reaction" dict "ctxData" $.ctxData "ActionURL" .ActionURL}}
15+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" .ActionURL}}
1616
{{end}}
1717
</div>

web_src/css/base.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,17 +1440,15 @@ table th[data-sortt-desc] .svg {
14401440
box-shadow: 0 0 0 1px var(--color-secondary) inset;
14411441
}
14421442

1443-
.emoji,
1444-
.reaction {
1443+
.emoji {
14451444
font-size: 1.25em;
14461445
line-height: var(--line-height-default);
14471446
font-style: normal !important;
14481447
font-weight: var(--font-weight-normal) !important;
14491448
vertical-align: -0.075em;
14501449
}
14511450

1452-
.emoji img,
1453-
.reaction img {
1451+
.emoji img {
14541452
border-width: 0 !important;
14551453
margin: 0 !important;
14561454
width: 1em !important;

0 commit comments

Comments
 (0)