Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Jul 21, 2024
1 parent e8b6df8 commit 3168e82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/v3/ui/components/search.templ
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/v3/ui/components/search_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions internal/v3/ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 3168e82

Please sign in to comment.