- 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  ## 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  ### After  ## 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  ### After  --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: 6543 <m.huber@kithara.com> Co-authored-by: Giteabot <teabot@gitea.io>
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2017 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package repo
 | |
| 
 | |
| import (
 | |
| 	"net/http"
 | |
| 	"strconv"
 | |
| 
 | |
| 	issues_model "code.gitea.io/gitea/models/issues"
 | |
| 	"code.gitea.io/gitea/modules/base"
 | |
| 	"code.gitea.io/gitea/modules/context"
 | |
| 	"code.gitea.io/gitea/modules/log"
 | |
| )
 | |
| 
 | |
| const (
 | |
| 	tplWatching base.TplName = "repo/issue/view_content/watching"
 | |
| )
 | |
| 
 | |
| // IssueWatch sets issue watching
 | |
| func IssueWatch(ctx *context.Context) {
 | |
| 	issue := GetActionIssue(ctx)
 | |
| 	if ctx.Written() {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
 | |
| 		if log.IsTrace() {
 | |
| 			if ctx.IsSigned {
 | |
| 				issueType := "issues"
 | |
| 				if issue.IsPull {
 | |
| 					issueType = "pulls"
 | |
| 				}
 | |
| 				log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
 | |
| 					"User in Repo has Permissions: %-+v",
 | |
| 					ctx.Doer,
 | |
| 					issue.PosterID,
 | |
| 					issueType,
 | |
| 					ctx.Repo.Repository,
 | |
| 					ctx.Repo.Permission)
 | |
| 			} else {
 | |
| 				log.Trace("Permission Denied: Not logged in")
 | |
| 			}
 | |
| 		}
 | |
| 		ctx.Error(http.StatusForbidden)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	watch, err := strconv.ParseBool(ctx.Req.PostForm.Get("watch"))
 | |
| 	if err != nil {
 | |
| 		ctx.ServerError("watch is not bool", err)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	if err := issues_model.CreateOrUpdateIssueWatch(ctx, ctx.Doer.ID, issue.ID, watch); err != nil {
 | |
| 		ctx.ServerError("CreateOrUpdateIssueWatch", err)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	ctx.Data["Issue"] = issue
 | |
| 	ctx.Data["IssueWatch"] = &issues_model.IssueWatch{IsWatching: watch}
 | |
| 	ctx.HTML(http.StatusOK, tplWatching)
 | |
| }
 |