Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce htmx and use it to avoid full page load on Subscribe and Follow #28908

Merged
merged 16 commits into from
Jan 30, 2024

Commits on Jan 23, 2024

  1. Introduce htmx and use it to avoid full page load on Subscribe and …

    …`Follow`
    
    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
    
    ### 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
      - `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
    
    ### Before
    
    ![subscribe_before](https://github.com/go-gitea/gitea/assets/20454870/cb2439a2-c3c0-425c-8d3c-5d646b1cdc28)
    
    ### After
    
    Also shows a small request loading indicator (the indicator should be worked on further in a future change)
    
    ![subscribe_after](https://github.com/go-gitea/gitea/assets/20454870/5e71a43e-9500-42af-8118-9d6441e8dc42)
    
    ## 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-swap="outerHTML"` to replace the card (as opposed to its inner
    content) with the new card that shows the new follower count and button
    color
    - 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/5df04537-0dd9-4e26-a5f4-73ae11e6d976)
    
    Signed-off-by: Yarden Shoham <[email protected]>
    yardenshoham committed Jan 23, 2024
    Configuration menu
    Copy the full SHA
    80f33f7 View commit details
    Browse the repository at this point in the history
  2. Add is-loading during request and disable autoscroll

    Signed-off-by: Yarden Shoham <[email protected]>
    yardenshoham committed Jan 23, 2024
    Configuration menu
    Copy the full SHA
    2096553 View commit details
    Browse the repository at this point in the history
  3. Change default swap style to outerHTML and disable url push

    Signed-off-by: Yarden Shoham <[email protected]>
    yardenshoham committed Jan 23, 2024
    Configuration menu
    Copy the full SHA
    90b2eb3 View commit details
    Browse the repository at this point in the history

Commits on Jan 27, 2024

  1. Apply spinner on entire profile

    Signed-off-by: Yarden Shoham <[email protected]>
    yardenshoham committed Jan 27, 2024
    Configuration menu
    Copy the full SHA
    55c4706 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'main' into htmx

    6543 authored Jan 27, 2024
    Configuration menu
    Copy the full SHA
    d312b30 View commit details
    Browse the repository at this point in the history
  3. Merge branch 'main' into htmx

    6543 authored Jan 27, 2024
    Configuration menu
    Copy the full SHA
    94c151c View commit details
    Browse the repository at this point in the history

Commits on Jan 28, 2024

  1. Configuration menu
    Copy the full SHA
    5cdc587 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5e27261 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    5fbbaa2 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    9d6015f View commit details
    Browse the repository at this point in the history

Commits on Jan 29, 2024

  1. Configuration menu
    Copy the full SHA
    910d973 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    42b1435 View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2024

  1. Configuration menu
    Copy the full SHA
    6859b1b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0d03be1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    acc2ca8 View commit details
    Browse the repository at this point in the history
  4. Remove window.htmx

    Signed-off-by: Yarden Shoham <[email protected]>
    yardenshoham committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    ae3b58f View commit details
    Browse the repository at this point in the history