Skip to content

Commit c6f1fb1

Browse files
HesterGsilverwindGiteaBotwxiaoguang
authored
Use fetch form action for lock/unlock/pin/unpin on sidebar (#25380)
Before: <img width="364" alt="Screen Shot 2023-06-20 at 11 59 11" src="https://github.com/go-gitea/gitea/assets/17645053/ad284b7e-8d21-43be-b178-bbcfd37cb5bd"> Might trigger many posts when keep clicking the buttons above. <img width="448" alt="Screen Shot 2023-06-20 at 11 52 28" src="https://github.com/go-gitea/gitea/assets/17645053/a60aa6ac-af74-45e4-b13a-512b436b81b0"> <img width="678" alt="Screen Shot 2023-06-20 at 11 52 37" src="https://github.com/go-gitea/gitea/assets/17645053/d6662700-3643-4cc7-a2ec-64e1c0f5fbdb"> After (PR sidebar, Same for issue): https://github.com/go-gitea/gitea/assets/17645053/9df3ad1f-e29c-439b-8bde-e6b917d63cc6 For delete, it is using `base/modal_actions_confirm` subtemplate, and we might need another general solution for this (maybe add another attribute to the subtemplate or something) --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: Giteabot <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent f0b773e commit c6f1fb1

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

routers/web/repo/issue_lock.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ func LockIssue(ctx *context.Context) {
2020
}
2121

2222
if issue.IsLocked {
23-
ctx.Flash.Error(ctx.Tr("repo.issues.lock_duplicate"))
24-
ctx.Redirect(issue.Link())
23+
ctx.JSONError(ctx.Tr("repo.issues.lock_duplicate"))
2524
return
2625
}
2726

2827
if !form.HasValidReason() {
29-
ctx.Flash.Error(ctx.Tr("repo.issues.lock.unknown_reason"))
30-
ctx.Redirect(issue.Link())
28+
ctx.JSONError(ctx.Tr("repo.issues.lock.unknown_reason"))
3129
return
3230
}
3331

@@ -40,7 +38,7 @@ func LockIssue(ctx *context.Context) {
4038
return
4139
}
4240

43-
ctx.Redirect(issue.Link())
41+
ctx.JSONRedirect(issue.Link())
4442
}
4543

4644
// UnlockIssue unlocks a previously locked issue.
@@ -51,8 +49,7 @@ func UnlockIssue(ctx *context.Context) {
5149
}
5250

5351
if !issue.IsLocked {
54-
ctx.Flash.Error(ctx.Tr("repo.issues.unlock_error"))
55-
ctx.Redirect(issue.Link())
52+
ctx.JSONError(ctx.Tr("repo.issues.unlock_error"))
5653
return
5754
}
5855

@@ -64,5 +61,5 @@ func UnlockIssue(ctx *context.Context) {
6461
return
6562
}
6663

67-
ctx.Redirect(issue.Link())
64+
ctx.JSONRedirect(issue.Link())
6865
}

routers/web/repo/issue_pin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func IssuePinOrUnpin(ctx *context.Context) {
3131
return
3232
}
3333

34-
ctx.Redirect(issue.Link())
34+
ctx.JSONRedirect(issue.Link())
3535
}
3636

3737
// IssueUnpin unpins a Issue

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@
556556
<div class="ui divider"></div>
557557

558558
{{if or .PinEnabled .Issue.IsPinned}}
559-
<form class="gt-mt-2" method="post" {{if $.NewPinAllowed}}action="{{.Issue.Link}}/pin"{{else}}data-tooltip-content="{{.locale.Tr "repo.issues.max_pinned"}}"{{end}}>
559+
<form class="gt-mt-2 form-fetch-action single-button-form" method="post" {{if $.NewPinAllowed}}action="{{.Issue.Link}}/pin"{{else}}data-tooltip-content="{{.locale.Tr "repo.issues.max_pinned"}}"{{end}}>
560560
{{$.CsrfTokenHtml}}
561561
<button class="fluid ui button {{if not $.NewPinAllowed}}disabled{{end}}">
562562
{{if not .Issue.IsPinned}}
@@ -599,7 +599,7 @@
599599
{{end}}
600600
</div>
601601

602-
<form class="ui form" action="{{.Issue.Link}}{{if .Issue.IsLocked}}/unlock{{else}}/lock{{end}}"
602+
<form class="ui form form-fetch-action" action="{{.Issue.Link}}{{if .Issue.IsLocked}}/unlock{{else}}/lock{{end}}"
603603
method="post">
604604
{{.CsrfTokenHtml}}
605605

web_src/css/modules/animations.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
content: "";
1818
position: absolute;
1919
display: block;
20-
height: 4rem;
21-
aspect-ratio: 1 / 1;
2220
left: 50%;
2321
top: 50%;
24-
max-height: 100%;
25-
max-width: 100%;
22+
height: min(4em, 66.6%);
23+
aspect-ratio: 1;
2624
transform: translate(-50%, -50%);
2725
animation: isloadingspin 500ms infinite linear;
2826
border-width: 4px;
@@ -35,6 +33,15 @@
3533
border-width: 2px;
3634
}
3735

36+
/* for single form button, the loading state should be on the button, but not go semi-transparent, just replace the text on the button with the loader. */
37+
form.single-button-form.is-loading > * {
38+
opacity: 1;
39+
}
40+
41+
form.single-button-form.is-loading .button {
42+
color: transparent;
43+
}
44+
3845
.markup pre.is-loading,
3946
.editor-loading.is-loading,
4047
.pdf-content.is-loading {

0 commit comments

Comments
 (0)