-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Don't do a full page load when clicking Watch
or Star
#29001
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
Changes from 4 commits
1be0880
2c5aaa5
d035242
fccd75a
bad8115
8885536
bcf26f2
07cc1db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,11 @@ func CreatePost(ctx *context.Context) { | |
handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) | ||
} | ||
|
||
const ( | ||
tplWatchUnwatch base.TplName = "repo/watch_unwatch" | ||
tplStarUnstar base.TplName = "repo/star_unstar" | ||
) | ||
|
||
// Action response for actions to a repository | ||
func Action(ctx *context.Context) { | ||
var err error | ||
|
@@ -334,6 +339,30 @@ func Action(ctx *context.Context) { | |
return | ||
} | ||
|
||
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) | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt it makes a significant difference, but can we extract There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ctx.RedirectToFirst(ctx.FormString("redirect_to"), ctx.Repo.RepoLink) | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
yardenshoham marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star"> | ||
yardenshoham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div class="ui labeled button" {{if not $.IsSigned}}data-tooltip-content="{{ctx.Locale.Tr "repo.star_guest_user"}}"{{end}}> | ||
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}> | ||
{{if $.IsStaringRepo}} | ||
yardenshoham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{svg "octicon-star-fill"}}<span class="text">{{ctx.Locale.Tr "repo.unstar"}}</span> | ||
{{else}} | ||
{{svg "octicon-star"}}<span class="text">{{ctx.Locale.Tr "repo.star"}}</span> | ||
{{end}} | ||
</button> | ||
<a hx-boost="false" class="ui basic label" href="{{$.RepoLink}}/stars"> | ||
{{CountFmt .Repository.NumStars}} | ||
</a> | ||
</div> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<form hx-boost="true" hx-target="this" method="post" action="{{$.RepoLink}}/action/{{if $.IsWatchingRepo}}un{{end}}watch"> | ||
<div class="ui labeled button" {{if not $.IsSigned}}data-tooltip-content="{{ctx.Locale.Tr "repo.watch_guest_user"}}"{{end}}> | ||
<button type="submit" class="ui compact small basic button"{{if not $.IsSigned}} disabled{{end}}> | ||
{{if $.IsWatchingRepo}} | ||
{{svg "octicon-eye-closed" 16}}<span class="text">{{ctx.Locale.Tr "repo.unwatch"}}</span> | ||
{{else}} | ||
{{svg "octicon-eye"}}<span class="text">{{ctx.Locale.Tr "repo.watch"}}</span> | ||
{{end}} | ||
</button> | ||
<a hx-boost="false" class="ui basic label" href="{{.RepoLink}}/watchers"> | ||
{{CountFmt .Repository.NumWatches}} | ||
</a> | ||
</div> | ||
</form> |
Uh oh!
There was an error while loading. Please reload this page.