Skip to content

Remove jQuery AJAX from the repo editor #29636

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

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

yardenshoham
Copy link
Member

@yardenshoham yardenshoham commented Mar 6, 2024

Preview Tab

  • Removed the jQuery AJAX call and replaced with our fetch wrapper
  • Tested the preview tab functionality and it works as before

Diff Tab

  • Removed the jQuery AJAX call and replaced with htmx
  • Tested the diff tab functionality and it works as before

htmx Attributes

  • hx-post="{{.RepoLink}}...": make a POST request to the endpoint
  • hx-indicator=".tab[data-tab='diff']": attach the loading indicator to the tab body
  • hx-target=".tab[data-tab='diff']": target the tab body for swapping with the response
  • hx-swap="innerHTML": swap the target's inner HTML
  • hx-include="#edit_area": include the value of the textarea (content) in the request body
  • hx-vals='{"context":"{{.BranchLink}}"}': include the context in the request body
  • hx-params="context,content": include only these keys in the request body

Demo using fetch and htmx instead of jQuery AJAX

demo

# Preview Tab
- Removed the jQuery AJAX call and replaced with our fetch wrapper
- Tested the preview tab functionality and it works as before

# Diff Tab
- Removed the jQuery AJAX call and replaced with htmx
- Tested the diff tab functionality and it works as before

## htmx Attributes
- `hx-post="{{.RepoLink}}..."`: make a POST request to the endpoint
- `hx-indicator=".tab[data-tab='diff']"`: attach the loading indicator to the tab body
- `hx-target=".tab[data-tab='diff']"`: target the tab body for swapping with the response
- `hx-swap="innerHTML"`: swap the targets inner HTML
- `hx-include="#edit_area"`: include the value of the textarea (content) in the request body
- `hx-vals='{"context":"{{.BranchLink}}"}'`: include the context in the request body
- `hx-params="context,content"`: include only these keys in the request body

Signed-off-by: Yarden Shoham <[email protected]>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 6, 2024
@yardenshoham yardenshoham added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Mar 6, 2024
@silverwind
Copy link
Member

silverwind commented Mar 6, 2024

Can something be done about the loading states? How about a bit bigger spinner on both tabs 2 and 3 and like 4rem padding? Also remove the "Loading..." text on tab 3. Ideally both tabs would have the same loading state. Make it look like the mermaid loader:

image

@yardenshoham
Copy link
Member Author

Can we maybe accept it as-is and handle style changes in a dedicated PR?

@silverwind
Copy link
Member

silverwind commented Mar 6, 2024

Hmm there is at least one visual change in your PR, that tiny spinner on first diff preview wasn't there before. How is it triggered?

@yardenshoham
Copy link
Member Author

yardenshoham commented Mar 6, 2024

htmx adds the is-loading class to the element that triggered the request or, if hx-indicator is specified, to the hx-indicator CSS selector

htmx.config.requestClass = 'is-loading';

@silverwind
Copy link
Member

Ok, can we just remove the Loading... text? It's now a duplicate indicator with that spinner being added.

@yardenshoham
Copy link
Member Author

yardenshoham commented Mar 6, 2024

Removed loading and added an empty div with padding: 4rem;, the GIF in the description is updated

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 6, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 6, 2024
@yardenshoham yardenshoham added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 7, 2024
@silverwind silverwind enabled auto-merge (squash) March 7, 2024 07:11
@silverwind silverwind merged commit c1331d1 into go-gitea:main Mar 7, 2024
@GiteaBot GiteaBot added this to the 1.23.0 milestone Mar 7, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 7, 2024
@yardenshoham yardenshoham deleted the repo-editor-jquery-ajax branch March 7, 2024 07:34
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 7, 2024
* giteaofficial/main:
  Remove jQuery AJAX from the repo editor (go-gitea#29636)
@lunny lunny modified the milestones: 1.23.0, 1.22.0 Mar 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants