diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index d81884ec62deb..0c5ebbee1450c 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -16,6 +16,7 @@ import ( const ( // tplExploreCode explore code page template tplExploreCode base.TplName = "explore/code" + tplSearchBody base.TplName = "code/search_body" ) // Code render explore code page @@ -42,8 +43,15 @@ func Code(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["PageIsViewCode"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplExploreCode + if isHtmxRequest { + template = tplSearchBody + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplExploreCode) + ctx.HTML(http.StatusOK, template) return } @@ -131,5 +139,5 @@ func Code(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplExploreCode) + ctx.HTML(http.StatusOK, template) } diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 3c0fa4bc00ea0..fab9d2277a5ce 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -12,7 +12,10 @@ import ( "code.gitea.io/gitea/modules/setting" ) -const tplSearch base.TplName = "repo/search" +const ( + tplSearch base.TplName = "repo/search" + tplSearchResult base.TplName = "repo/search_result" +) // Search render repository search page func Search(ctx *context.Context) { @@ -32,8 +35,15 @@ func Search(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["PageIsViewCode"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplSearch + if isHtmxRequest { + template = tplSearchResult + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplSearch) + ctx.HTML(http.StatusOK, template) return } @@ -63,5 +73,5 @@ func Search(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplSearch) + ctx.HTML(http.StatusOK, template) } diff --git a/routers/web/user/code.go b/routers/web/user/code.go index ee514a7cfe535..dfd27ff4c38bf 100644 --- a/routers/web/user/code.go +++ b/routers/web/user/code.go @@ -15,7 +15,8 @@ import ( ) const ( - tplUserCode base.TplName = "user/code" + tplUserCode base.TplName = "user/code" + tplSearchBody base.TplName = "code/search_body" ) // CodeSearch render user/organization code search page @@ -47,8 +48,15 @@ func CodeSearch(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["IsCodePage"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplUserCode + if isHtmxRequest { + template = tplSearchBody + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplUserCode) + ctx.HTML(http.StatusOK, template) return } @@ -116,5 +124,5 @@ func CodeSearch(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplUserCode) + ctx.HTML(http.StatusOK, template) } diff --git a/templates/code/search_body.tmpl b/templates/code/search_body.tmpl new file mode 100644 index 0000000000000..c9c94aeef37a6 --- /dev/null +++ b/templates/code/search_body.tmpl @@ -0,0 +1,12 @@ +
+
+ {{if .CodeIndexerUnavailable}} +
+

{{ctx.Locale.Tr "explore.code_search_unavailable"}}

+
+ {{else}} + {{template "code/searchresults" .}} + {{end}} +
+ {{template "base/paginate" .}} +
diff --git a/templates/code/searchcombo.tmpl b/templates/code/searchcombo.tmpl index 48dc13b47be74..cb3fff3442a4a 100644 --- a/templates/code/searchcombo.tmpl +++ b/templates/code/searchcombo.tmpl @@ -1,17 +1,3 @@ {{template "code/searchform" .}}
-
- {{if .CodeIndexerUnavailable}} -
-

{{ctx.Locale.Tr "explore.code_search_unavailable"}}

-
- {{else if .SearchResults}} -

- {{ctx.Locale.Tr "explore.code_search_results" (.Keyword|Escape) | Str2html}} -

- {{template "code/searchresults" .}} - {{else if .Keyword}} -
{{ctx.Locale.Tr "explore.code_no_results"}}
- {{end}} -
-{{template "base/paginate" .}} +{{template "code/search_body" .}} diff --git a/templates/code/searchform.tmpl b/templates/code/searchform.tmpl index fae1340046838..8b77f4f2ad920 100644 --- a/templates/code/searchform.tmpl +++ b/templates/code/searchform.tmpl @@ -1,4 +1,4 @@ -
+
{{template "shared/searchinput" dict "Value" .Keyword "Disabled" .CodeIndexerUnavailable}}