From 5b10aed601e8c3d8bd7820876920705f4d31b07f Mon Sep 17 00:00:00 2001 From: maddalax Date: Tue, 1 Oct 2024 17:19:38 -0500 Subject: [PATCH] cleanup --- examples/chat/partials/index.go | 7 +++---- framework/h/base.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/chat/partials/index.go b/examples/chat/partials/index.go index d38daec..4607475 100644 --- a/examples/chat/partials/index.go +++ b/examples/chat/partials/index.go @@ -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(), ) } diff --git a/framework/h/base.go b/framework/h/base.go index 01ecd76..027e013 100644 --- a/framework/h/base.go +++ b/framework/h/base.go @@ -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))