diff options
author | Yarden Shoham <git@yardenshoham.com> | 2024-01-20 21:44:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 20:44:51 +0100 |
commit | 14f6fcf4481cedc2cd9d5ea5aaff88e109089e1f (patch) | |
tree | 62f6fff4a7dbacabc945852528a79d206e7c0027 /templates/repo/issue | |
parent | 80d48621cdf484247f70ddd653fb4c47a640317a (diff) | |
download | gitea-14f6fcf4481cedc2cd9d5ea5aaff88e109089e1f.tar.gz gitea-14f6fcf4481cedc2cd9d5ea5aaff88e109089e1f.zip |
Don't do a full page load when clicking the subscribe button (#28871)
- Refactor the form around the subscribe button into its own template
- Use htmx to perform the form submission
- `hx-boost="true"` to prevent the default form submission behavior of a
full page load
- `hx-sync="this:replace"` to replace the current request (in case the
button is clicked again before the response is returned)
- `hx-target="this"` to replace the form tag with the new form tag
- `hx-push-url="false"` to disable a change to the URL
- `hx-swap="show:no-scroll"` to preserve the scroll position
- Change the backend response to return a `<form>` tag instead of a
redirect to the issue page
- Include `htmx.org` in javascript imports
This change introduces htmx with the hope we could use it to make Gitea
more reactive while keeping our "HTML rendered on the server" approach.
# Before
![before](https://github.com/go-gitea/gitea/assets/20454870/4ec3e81e-4dbf-4338-9968-b0655c276d4c)
# After
![after](https://github.com/go-gitea/gitea/assets/20454870/8c8841af-9bfe-40b2-b1cd-cd1f3c90ba4d)
---------
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Diffstat (limited to 'templates/repo/issue')
-rw-r--r-- | templates/repo/issue/view_content/sidebar.tmpl | 14 | ||||
-rw-r--r-- | templates/repo/issue/view_content/watching.tmpl | 13 |
2 files changed, 14 insertions, 13 deletions
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 4334e4bcbd..6c13eef023 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -270,19 +270,7 @@ <div class="ui watching"> <span class="text"><strong>{{ctx.Locale.Tr "notification.notifications"}}</strong></span> <div class="gt-mt-3"> - <form method="post" action="{{.Issue.Link}}/watch"> - <input type="hidden" name="watch" value="{{if $.IssueWatch.IsWatching}}0{{else}}1{{end}}"> - {{$.CsrfTokenHtml}} - <button class="fluid ui button"> - {{if $.IssueWatch.IsWatching}} - {{svg "octicon-mute" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.issues.unsubscribe"}} - {{else}} - {{svg "octicon-unmute" 16 "gt-mr-3"}} - {{ctx.Locale.Tr "repo.issues.subscribe"}} - {{end}} - </button> - </form> + {{template "repo/issue/view_content/watching" .}} </div> </div> {{end}} diff --git a/templates/repo/issue/view_content/watching.tmpl b/templates/repo/issue/view_content/watching.tmpl new file mode 100644 index 0000000000..06b9d9af33 --- /dev/null +++ b/templates/repo/issue/view_content/watching.tmpl @@ -0,0 +1,13 @@ +<form hx-boost="true" hx-sync="this:replace" hx-target="this" hx-push-url="false" hx-swap="show:no-scroll" method="post" action="{{.Issue.Link}}/watch"> + <input type="hidden" name="watch" value="{{if $.IssueWatch.IsWatching}}0{{else}}1{{end}}"> + {{$.CsrfTokenHtml}} + <button class="fluid ui button"> + {{if $.IssueWatch.IsWatching}} + {{svg "octicon-mute" 16 "gt-mr-3"}} + {{ctx.Locale.Tr "repo.issues.unsubscribe"}} + {{else}} + {{svg "octicon-unmute" 16 "gt-mr-3"}} + {{ctx.Locale.Tr "repo.issues.subscribe"}} + {{end}} + </button> +</form> |