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

Don't do a full page load when clicking Watch or Star #29001

Merged
merged 8 commits into from
Feb 5, 2024

Conversation

yardenshoham
Copy link
Member

  • The watch/unwatch button and star/unstar get their own template
  • The backend returns HTML instead of redirect

Before

before

After

after

- The watch/unwatch button and star/unstar get their own template
- The backend returns HTML instead of redirect

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 Jan 31, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 31, 2024
templates/repo/star_unstar.tmpl Show resolved Hide resolved
@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 Jan 31, 2024
Comment on lines 342 to 364
switch ctx.Params(":action") {
case "watch", "unwatch":
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
case "star", "unstar":
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
}

switch ctx.Params(":action") {
case "watch", "unwatch", "star", "unstar":
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
if err != nil {
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
return
}
}

switch ctx.Params(":action") {
case "watch", "unwatch":
ctx.HTML(http.StatusOK, tplWatchUnwatch)
return
case "star", "unstar":
ctx.HTML(http.StatusOK, tplStarUnstar)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it makes a significant difference, but can we extract ctx.Params(":action") to a variable and use that instead of four lookups?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest code? I am not sure how exactly you want it

routers/web/repo/repo.go Show resolved Hide resolved
templates/repo/star_unstar.tmpl Show resolved Hide resolved
templates/repo/star_unstar.tmpl Show resolved Hide resolved
@yardenshoham
Copy link
Member Author

@jolheiser I had to revert because the RepoAssignment middleware writes to IsStaring

@lunny lunny added the topic/ux How users interact with Gitea label Feb 4, 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 Feb 5, 2024
@yardenshoham yardenshoham added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 5, 2024
routers/web/repo/repo.go Outdated Show resolved Hide resolved
@wxiaoguang wxiaoguang removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 5, 2024
Signed-off-by: Yarden Shoham <[email protected]>
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 5, 2024
@wxiaoguang wxiaoguang enabled auto-merge (squash) February 5, 2024 09:32
@wxiaoguang wxiaoguang merged commit 6992ef9 into go-gitea:main Feb 5, 2024
25 checks passed
@wxiaoguang wxiaoguang deleted the watch-unwatch-star-unstar branch February 5, 2024 09:56
@GiteaBot GiteaBot added this to the 1.22.0 milestone Feb 5, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 5, 2024
@gwymor gwymor mentioned this pull request Feb 6, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 7, 2024
* giteaofficial/main:
  Hide code links on release page if user cannot read code (go-gitea#29064)
  [skip ci] Updated translations via Crowdin
  Don't do a full page load when clicking `Watch` or `Star` (go-gitea#29001)
  Remove useless template file (go-gitea#29053)
  Fix typos in the documentation (go-gitea#29048)
  Move some repository transfer functions to service layer (go-gitea#28855)
  Propagate install_if and provider_priority to APKINDEX (go-gitea#28899)
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
…9001)

- The watch/unwatch button and star/unstar get their own template
- The backend returns HTML instead of redirect

---------

Signed-off-by: Yarden Shoham <[email protected]>
Co-authored-by: John Olheiser <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. topic/ux How users interact with Gitea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants