Skip to content

Commit

Permalink
removed app.PostReleaser().
Browse files Browse the repository at this point in the history
now only htmx.PostReleaser() is in use.
  • Loading branch information
bengarrett committed Mar 24, 2024
1 parent 5db8499 commit 35bf1e7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 70 deletions.
64 changes: 2 additions & 62 deletions handler/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/Defacto2/releaser"
"github.com/Defacto2/releaser/initialism"
namer "github.com/Defacto2/releaser/name"
"github.com/Defacto2/server/handler/download"
"github.com/Defacto2/server/handler/sess"
"github.com/Defacto2/server/internal/archive"
Expand Down Expand Up @@ -1030,22 +1029,6 @@ func PostName(logr *zap.SugaredLogger, c echo.Context, mode FileSearch) error {
return nil
}

// PostReleaser is the handler for the releaser search form post page.
func PostReleaser(logr *zap.SugaredLogger, c echo.Context) error {
const name = "searchList"
if logr == nil {
return InternalErr(logr, c, name, ErrZap)
}
input := c.FormValue("releaser-data-list")
val := helper.TrimRoundBraket(input)
slug := helper.Slug(val)
if slug == "" {
return SearchReleaser(logr, c)
}
// note, the redirect to a GET only works with 301 and 404 status codes.
return c.Redirect(http.StatusMovedPermanently, "/g/"+slug)
}

// PouetCache parses the cached data for the Pouet production votes.
// If the cache is valid it is returned as JSON response.
// If the cache is invalid or corrupt an error will be returned
Expand Down Expand Up @@ -1711,27 +1694,9 @@ func SearchFile(logr *zap.SugaredLogger, c echo.Context) error {
return nil
}

// SearchReleaserX is the handler for the Releaser Search page.
func SearchReleaserX(logr *zap.SugaredLogger, c echo.Context) error {
const title, name = "Search for releasers", "searchHtmx"
if logr == nil {
return InternalErr(logr, c, name, ErrZap)
}
data := empty(c)
data["description"] = "Search form to discover releasers."
data["logo"] = title
data["title"] = title
data["info"] = "search for a group, initialism, magazine, board, or site"
err := c.Render(http.StatusOK, name, data)
if err != nil {
return InternalErr(logr, c, name, err)
}
return nil
}

// SearchReleaser is the handler for the Releaser Search page.
func SearchReleaser(logr *zap.SugaredLogger, c echo.Context) error {
const title, name = "Search for releasers", "searchList"
const title, name = "Search for releasers", "searchHtmx"
if logr == nil {
return InternalErr(logr, c, name, ErrZap)
}
Expand All @@ -1740,32 +1705,7 @@ func SearchReleaser(logr *zap.SugaredLogger, c echo.Context) error {
data["logo"] = title
data["title"] = title
data["info"] = "search for a group, initialism, magazine, board, or site"
ctx := context.Background()
db, err := postgres.ConnectDB()
if err != nil {
return DatabaseErr(logr, c, name, err)
}
defer db.Close()
x := model.ReleaserNames{}
if err := x.List(ctx, db); err != nil {
return DatabaseErr(logr, c, name, err)
}
s := make([]string, len(x))
for i, v := range x {
id := strings.TrimSpace(v.Name)
slug := helper.Slug(id)
// use namer.Humanized instead of the releaser.link func as it is far more performant
name, _ := namer.Humanize(namer.Path(slug))
ism := initialism.Initialism(initialism.Path(slug))
opt := name
if len(ism) > 0 {
opt = fmt.Sprintf("%s (%s)", name, strings.Join(ism, ", "))
}
s[i] = opt
}
data["releasers"] = s

err = c.Render(http.StatusOK, name, data)
err := c.Render(http.StatusOK, name, data)
if err != nil {
return InternalErr(logr, c, name, err)
}
Expand Down
4 changes: 2 additions & 2 deletions handler/htmx/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Routes for the /htmx sub-route group that returns HTML fragments
// using the htmx library for AJAX responses.
func Routes(logr *zap.SugaredLogger, e *echo.Echo) *echo.Echo {
e.POST("/search/releaser-x", func(x echo.Context) error {
e.POST("/search/releaser", func(x echo.Context) error {
return PostReleaser(logr, x)
})
return e
Expand All @@ -34,7 +34,7 @@ func GlobTo(name string) string {
return strings.Join([]string{"view", "htmx", name}, "/")
}

// PostReleaser is a handler for the /search/releaser-x route.
// PostReleaser is a handler for the /search/releaser route.
func PostReleaser(logr *zap.SugaredLogger, c echo.Context) error {
const maxResults = 14
ctx := context.Background()
Expand Down
6 changes: 2 additions & 4 deletions handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Defacto2/releaser"
"github.com/Defacto2/server/handler/app"
"github.com/Defacto2/server/handler/htmx"
"github.com/Defacto2/server/internal/config"
"github.com/Defacto2/server/internal/helper"
"github.com/gorilla/sessions"
Expand Down Expand Up @@ -248,9 +249,6 @@ func (c Configuration) Routes(e *echo.Echo, public embed.FS) (*echo.Echo, error)
search.GET("/releaser", func(x echo.Context) error {
return app.SearchReleaser(logr, x)
})
search.GET("/releaser-x", func(x echo.Context) error {
return app.SearchReleaserX(logr, x)
})
search.GET("/result", func(x echo.Context) error {
// this legacy get result should be kept for (osx.xml) opensearch compatibility
// and to keep possible backwards compatibility with third party site links.
Expand All @@ -265,7 +263,7 @@ func (c Configuration) Routes(e *echo.Echo, public embed.FS) (*echo.Echo, error)
return app.PostFilename(logr, x)
})
search.POST("/releaser", func(x echo.Context) error {
return app.PostReleaser(logr, x)
return htmx.PostReleaser(logr, x)
})

// Uploader for anonymous client uploads
Expand Down
1 change: 0 additions & 1 deletion view/app/layout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
Search
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/search/releaser-x">Releasers X</a></li>
<li><a class="dropdown-item" href="/search/releaser">Releasers</a></li>
<li><a class="dropdown-item" href="/search/file">Files</a></li>
<li><a class="dropdown-item" href="/search/desc">Descriptions</a></li>
Expand Down
2 changes: 1 addition & 1 deletion view/app/searchHtmx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<input type="text" spellcheck="false" autofocus
class="form-control" id="releaserSearch" name="releaser-search"
hx-post="/search/releaser-x"
hx-post="/search/releaser"
hx-target="#search-results"
hx-trigger="keyup changed delay:500ms"
hx-indicator="#indicator"
Expand Down

0 comments on commit 35bf1e7

Please sign in to comment.