You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/routers/web/repo
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>
1 year ago
..
actions Fix incorrect action duration time when rerun the job before executed once (#28364) 1 year ago
setting Preserve BOM in web editor (#28935) 1 year ago
activity.go
attachment.go Even more `db.DefaultContext` refactor (#27352) 1 year ago
blame.go Use information from previous blame parts (#28572) 1 year ago
branch.go Adjust object format interface (#28469) 1 year ago
cherry_pick.go Upgrade to golangci-lint@v1.55.0 (#27756) 1 year ago
commit.go Simplify how git repositories are opened (#28937) 1 year ago
compare.go Simplify how git repositories are opened (#28937) 1 year ago
download.go Less naked returns (#25713) 2 years ago
editor.go Preserve BOM in web editor (#28935) 1 year ago
editor_test.go Simplify how git repositories are opened (#28937) 1 year ago
find.go
githttp.go Adjust object format interface (#28469) 1 year ago
githttp_test.go Fix http protocol auth (#27875) 1 year ago
helper.go Improve tree not found page (#26570) 1 year ago
helper_test.go Make web context initialize correctly for different cases (#26726) 1 year ago
issue.go Add ability to see open and closed issues at the same time (#28757) 1 year ago
issue_content_history.go Fix missing check (#28406) 1 year ago
issue_dependency.go Upgrade to golangci-lint@v1.55.0 (#27756) 1 year ago
issue_label.go Even more `db.DefaultContext` refactor (#27352) 1 year ago
issue_label_test.go Move web/api context related testing function into a separate package (#26859) 1 year ago
issue_lock.go Penultimate round of `db.DefaultContext` refactor (#27414) 1 year ago
issue_pin.go Fix missing check (#28406) 1 year ago
issue_stopwatch.go Final round of `db.DefaultContext` refactor (#27587) 1 year ago
issue_test.go
issue_timetrack.go Final round of `db.DefaultContext` refactor (#27587) 1 year ago
issue_watch.go Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (#28908) 1 year ago
main_test.go make writing main test easier (#27270) 1 year ago
middlewares.go Fix viewing wiki commit on empty repo (#28040) 1 year ago
migrate.go Next round of `db.DefaultContext` refactor (#27089) 1 year ago
milestone.go Rework markup link rendering (#26745) 1 year ago
packages.go Fix the display of org level badges (#26504) 1 year ago
patch.go Upgrade to golangci-lint@v1.55.0 (#27756) 1 year ago
projects.go Rework markup link rendering (#26745) 1 year ago
projects_test.go Move web/api context related testing function into a separate package (#26859) 1 year ago
pull.go Simplify how git repositories are opened (#28937) 1 year ago
pull_review.go Don't reload timeline page when (un)resolving or replying conversation (#28654) 1 year ago
release.go Rework markup link rendering (#26745) 1 year ago
release_test.go Move more functions to db.Find (#28419) 1 year ago
render.go Preserve BOM in web editor (#28935) 1 year ago
repo.go Add support for sha256 repositories (#23894) 1 year ago
search.go Refactor indexer (#25174) 2 years ago
topic.go Next round of `db.DefaultContext` refactor (#27089) 1 year ago
treelist.go
view.go Preserve BOM in web editor (#28935) 1 year ago
view_test.go
wiki.go Simplify how git repositories are opened (#28937) 1 year ago
wiki_test.go Simplify how git repositories are opened (#28937) 1 year ago