1
1
Fork 1
mirror of https://github.com/go-gitea/gitea.git synced 2024-06-01 12:06:09 +02:00
gitea/routers/web
Yarden Shoham 3e8414179c
Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (#28908)
- Closes https://github.com/go-gitea/gitea/issues/28880

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.

- Add `htmx.js` that imports `htmx.org` and initializes error toasts
- Place `hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'` on the
`<body>` tag so every request that htmx sends is authenticated
- Place `hx-swap="outerHTML"` on the `<body>` tag so the response of
each htmx request replaces the tag it targets (as opposed to its inner
content)
- Place `hx-push-url="false"` on the `<body>` tag so no changes to the
URL happen in `<form>` tags
- Add the `is-loading` class during request

### Error toasts in action


![errors](https://github.com/go-gitea/gitea/assets/20454870/181a1beb-1cb8-4858-abe8-fa1fc3f5b8f3)

## Don't do a full page load when clicking the subscribe button
- 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
- Change the backend response to return a `<form>` tag instead of a
redirect to the issue page

### Before


![subscribe_before](https://github.com/go-gitea/gitea/assets/20454870/cb2439a2-c3c0-425c-8d3c-5d646b1cdc28)

### After


![subscribe_after](https://github.com/go-gitea/gitea/assets/20454870/6fcd77d8-7b11-40b0-af4f-b152aaad787c)

## Don't do a full page load when clicking the follow button
- Use htmx to perform the button request
- `hx-post="{{.ContextUser.HomeLink}}?action=follow"` to send a POST
request to follow the user
- `hx-target="#profile-avatar-card"` to target the card div for
replacement
- `hx-indicator="#profile-avatar-card"` to place the loading indicator
on the card
- Change the backend response to return a `<div>` tag (the card) instead
of a redirect to the user page

### Before


![follow_before](https://github.com/go-gitea/gitea/assets/20454870/a210b643-6e74-4ff9-8e61-d658c62edf1f)

### After


![follow_after](https://github.com/go-gitea/gitea/assets/20454870/5bb19ae9-0d59-4ae3-b538-4c83334e4722)

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: 6543 <m.huber@kithara.com>
Co-authored-by: Giteabot <teabot@gitea.io>
2024-01-30 15:45:54 +01:00
..
admin Allow to sync tags from admin dashboard (#28045) 2024-01-24 03:02:04 +00:00
auth Normalize oauth email username (#28561) 2024-01-03 18:48:20 -06:00
devtest Make "cancel" buttons have proper type in modal forms (#25618) 2023-07-03 14:04:50 +08:00
events Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
explore Allow to set explore page default sort (#27951) 2023-11-09 10:11:45 +00:00
feed Set the `isPermaLink` attribute to `false` in the `guid` sub-element (#28860) 2024-01-20 02:38:16 +00:00
healthcheck Always enable caches (#28527) 2023-12-19 09:29:05 +00:00
misc Refactor CORS handler (#28587) 2023-12-25 20:13:18 +08:00
org Rework markup link rendering (#26745) 2024-01-15 08:49:24 +00:00
repo Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (#28908) 2024-01-30 15:45:54 +01:00
shared Simplify how git repositories are opened (#28937) 2024-01-27 21:09:51 +01:00
user Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (#28908) 2024-01-30 15:45:54 +01:00
base.go Fix panic in storageHandler (#27446) 2023-10-06 13:23:14 +00:00
githttp.go Add support for sha256 repositories (#23894) 2024-01-19 17:05:02 +01:00
goget.go Support SSH for go get (#24664) 2023-05-12 09:44:37 +00:00
home.go Enhanced auth token / remember me (#27606) 2023-10-14 00:56:41 +00:00
metrics.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
nodeinfo.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
swagger_json.go Start using template context function (#26254) 2023-08-08 01:22:47 +00:00
web.go Fix inconsistent naming of OAuth 2.0 `ENABLE` setting (#28951) 2024-01-28 12:36:44 +00:00
webfinger.go Add a link to OpenID Issuer URL in WebFinger response (#26000) 2023-07-20 16:02:45 +08:00