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/web_src/js/features
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
..
admin Use appSubUrl for OAuth2 callback URL tip (#28266) 1 year ago
comp Update JS dependencies (#27922) 1 year ago
captcha.js Add new captcha: cloudflare turnstile (#22369) 2 years ago
citation.js Don't show unnecessary citation JS error on UI (#28433) 1 year ago
clipboard.js Clipboard copy enhancements (#27669) 1 year ago
codeeditor.js Preserve BOM in web editor (#28935) 1 year ago
colorpicker.js JS refactors (#22227) 2 years ago
common-global.js Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (#28908) 1 year ago
common-issue-list.js Polyfill SubmitEvent for PaleMoon (#28441) 1 year ago
common-issue-list.test.js Use vitest globals (#27102) 1 year ago
common-organization.js Fix Org edit page bugs: renaming detection, maxlength (#24161) 2 years ago
contextpopup.js Fix issue and commit status popup padding (#25254) 2 years ago
copycontent.js Use fetch helpers instead of fetch (#27026) 1 year ago
dropzone.js JS refactors (#22227) 2 years ago
emoji.js Update JS and PY dependencies (#27501) 1 year ago
eventsource.sharedworker.js Fix the JS error "EventSource is not defined" caused by some non-standard browsers (#20584) 3 years ago
file-fold.js Update JS dependencies (#27922) 1 year ago
heatmap.js Remove fomantic loader module (#26670) 1 year ago
imagediff.js Replace ajax with fetch, improve image diff (#27267) 1 year ago
install.js Use fetch helpers instead of fetch (#27026) 1 year ago
notification.js Fix notification list bugs (#25781) 2 years ago
org-team.js Update JS dependencies (#27922) 1 year ago
pull-view-file.js Update JS dependencies (#27922) 1 year ago
repo-branch.js Display warning when user try to rename default branch (#24512) 2 years ago
repo-code.js Change form actions to fetch for submit review box (#25219) 2 years ago
repo-code.test.js Use vitest globals (#27102) 1 year ago
repo-commit.js Add `Hide/Show all checks` button to commit status check (#26284) 1 year ago
repo-common.js Improve "language stats" UI (#26968) 1 year ago
repo-diff-commit.js Use fetch helpers instead of fetch (#27026) 1 year ago
repo-diff-commitselect.js Add commits dropdown in PR files view and allow commit by commit review (#25528) 2 years ago
repo-diff-filetree.js JS refactors (#22227) 2 years ago
repo-diff.js Polyfill SubmitEvent for PaleMoon (#28441) 1 year ago
repo-editor.js Update JS dependencies (#27922) 1 year ago
repo-findfile.js Update JS dependencies (#27922) 1 year ago
repo-findfile.test.js Use vitest globals (#27102) 1 year ago
repo-graph.js Refactor hiding-methods, remove jQuery show/hide, remove `.hide` class, remove inline style=display:none (#22950) 2 years ago
repo-home.js Fix edit topic UI (#27925) 1 year ago
repo-issue-content.js Improve issue history dialog and make poster can delete their own history (#27323) 1 year ago
repo-issue-list.js Hide archived labels by default from the suggestions when assigning labels for an issue (#27451) 1 year ago
repo-issue-pr-form.js JS refactors (#22227) 2 years ago
repo-issue-pr-status.js Fix the overflow style for "Hide all checks" (#27932) 1 year ago
repo-issue.js Fix incorrect URL for "Reference in New Issue" (#28716) 1 year ago
repo-legacy.js Update JS dependencies (#27922) 1 year ago
repo-migrate.js Use fetch helpers instead of fetch (#27026) 1 year ago
repo-migration.js Use "input" event instead of "keyup" event for migration form (#26602) 1 year ago
repo-projects.js Fix duplicate project board when hitting `enter` key (#27746) 1 year ago
repo-release.js Update JS dependencies, add new eslint rules (#24597) 2 years ago
repo-settings.js Add branch protection setting for ignoring stale approvals (#28498) 1 year ago
repo-template.js Add status indicator on main home screen for each repo (#24638) 2 years ago
repo-unicode-escape.js Improve accessibility when (re-)viewing files (#24817) 2 years ago
repo-wiki.js Improve wiki sidebar and TOC (#25460) 2 years ago
sshkey-helper.js
stopwatch.js Move helpers to be prefixed with `gt-` (#22879) 2 years ago
tablesort.js JS refactors (#22227) 2 years ago
tribute.js Avoiding accessing undefined mentionValues (#26461) 2 years ago
user-auth-webauthn.js Use fetch helpers instead of fetch (#27026) 1 year ago
user-auth.js Show the mismatched ROOT_URL warning on the sign-in page if OAuth2 is enabled (#25947) 2 years ago
user-settings.js Refactor hiding-methods, remove jQuery show/hide, remove `.hide` class, remove inline style=display:none (#22950) 2 years ago