This commit is contained in:
maddalax 2024-10-01 17:19:38 -05:00
parent d37bbd85a5
commit 5b10aed601
2 changed files with 15 additions and 4 deletions

View file

@ -36,13 +36,12 @@ func CreateOrJoinRoom(ctx *h.RequestContext) *h.Partial {
Path: "/",
Expires: time.Now().Add(24 * 30 * time.Hour),
}
return h.SwapManyPartialWithHeaders(
ctx,
return h.RedirectPartialWithHeaders(
path,
h.NewHeaders(
"Set-Cookie", cookie.String(),
"HX-Redirect", path,
),
h.Fragment(),
)
}

View file

@ -51,6 +51,18 @@ func SwapManyPartialWithHeaders(ctx *RequestContext, headers *Headers, swaps ...
)
}
func RedirectPartial(path string) *Partial {
return RedirectPartialWithHeaders(path, NewHeaders())
}
func RedirectPartialWithHeaders(path string, headers *Headers) *Partial {
h := *NewHeaders("HX-Redirect", path)
for k, v := range *headers {
h[k] = v
}
return NewPartialWithHeaders(&h, Fragment())
}
func SwapPartial(ctx *RequestContext, swap *Element) *Partial {
return NewPartial(
SwapMany(ctx, swap))