diff --git a/internal/v3/ui/components/search.templ b/internal/v3/ui/components/search.templ index 497669b..8c59967 100644 --- a/internal/v3/ui/components/search.templ +++ b/internal/v3/ui/components/search.templ @@ -18,7 +18,7 @@ templ SearchView(query string, modules []*gen.Module) { placeholder="Name, author, version..." hx-get="/search" hx-params="*" - hx-trigger="input changed delay:500ms, search, load" + hx-trigger="input changed delay:500ms, search" hx-target="#search-results" hx-select="#search-results" hx-swap="outerHTML" diff --git a/internal/v3/ui/components/search_templ.go b/internal/v3/ui/components/search_templ.go index 95e8941..96425ca 100644 --- a/internal/v3/ui/components/search_templ.go +++ b/internal/v3/ui/components/search_templ.go @@ -44,7 +44,7 @@ func SearchView(query string, modules []*gen.Module) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" placeholder=\"Name, author, version...\" hx-get=\"/search\" hx-params=\"*\" hx-trigger=\"input changed delay:500ms, search, load\" hx-target=\"#search-results\" hx-select=\"#search-results\" hx-swap=\"outerHTML\" hx-replace-url=\"true\">") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" placeholder=\"Name, author, version...\" hx-get=\"/search\" hx-params=\"*\" hx-trigger=\"input changed delay:500ms, search\" hx-target=\"#search-results\" hx-select=\"#search-results\" hx-swap=\"outerHTML\" hx-replace-url=\"true\">
ModuleAuthorVersion
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/v3/ui/handlers.go b/internal/v3/ui/handlers.go index f60e19b..88fb8af 100644 --- a/internal/v3/ui/handlers.go +++ b/internal/v3/ui/handlers.go @@ -14,7 +14,13 @@ import ( ) func IndexHandler(w http.ResponseWriter, r *http.Request) { - templ.Handler(components.Page("Gorge", components.SearchView("", []*gen.Module{}))).ServeHTTP(w, r) + modules, err := backend.ConfiguredBackend.GetAllModules() + if err != nil { + w.WriteHeader(500) + log.Log.Error(err) + return + } + templ.Handler(components.Page("Gorge", components.SearchView("", modules))).ServeHTTP(w, r) } func SearchHandler(w http.ResponseWriter, r *http.Request) { @@ -29,7 +35,13 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) { filtered := []*gen.Module{} for _, module := range modules { - if strings.Contains(module.Name, query) || strings.Contains(module.Owner.Username, query) || strings.Contains(module.CurrentRelease.Version, query) { + ok := true + for _, q := range strings.Split(query, " ") { + if !strings.Contains(module.Name, q) && !strings.Contains(module.Owner.Username, q) && !strings.Contains(module.CurrentRelease.Version, q) { + ok = false + } + } + if ok { filtered = append(filtered, module) } }
ModuleAuthorVersion