Skip to content

Commit aed6dd0

Browse files
feat: add hx-boost to body
1 parent 1695b93 commit aed6dd0

11 files changed

+75
-31
lines changed

pkg/htmx/htmx.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func SetReswap(w http.ResponseWriter) {
8484
}
8585

8686
// SetRetarget is a CSS selector that updates the target of the content update to a different element on the page.
87-
func SetRetarget(w http.ResponseWriter) {
88-
w.Header().Set("HX-Retarget", "true")
87+
func SetRetarget(w http.ResponseWriter, target string) {
88+
w.Header().Set("HX-Retarget", target)
8989
}
9090

9191
// SetReselect is a CSS selector that allows you to choose which part of the response is used to be swapped in.

web/components/attachment_card.templ

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ templ AttachmentCard(props AttachmentCardProps) {
1717
<div class="card-body">
1818
<h2 class="card-title break-all">{ props.Attachment.Name }</h2>
1919
<div class="card-actions justify-end">
20-
<a href={ routes.AttachmentFile(props.Attachment.FileName()).URLQuery("download=1") } class="btn btn-primary">Download</a>
20+
<a hx-boost="false" href={ routes.AttachmentFile(props.Attachment.FileName()).URLQuery("download=1") } class="btn btn-primary">Download</a>
2121
</div>
2222
</div>
2323
</div>

web/components/attachment_card_templ.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/components/base.templ

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ templ Base(head, body templ.Component, csrfToken string) {
1919
<meta name="gorilla.csrf.Token" content={ csrfToken } />
2020
{! head }
2121
</head>
22-
<body>
22+
<body hx-boost="true">
2323
{! body }
2424
</body>
2525
</html>

web/components/base_templ.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/http/router.go

+21-12
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ func NewRouter(ct pages.Controller, app core.App, fileFS fs.FS, csrfSecret []byt
4949
pages.IndexView(ct, app))
5050

5151
// Envelope
52-
r.Get(routes.EnvelopeList().String(),
53-
pages.EnvelopeListView(ct, app))
5452
r.Get(routes.EnvelopeCreate().String(),
5553
pages.EnvelopeCreateView(ct, app))
5654
r.Post(routes.EnvelopeCreate().String(),
@@ -61,18 +59,26 @@ func NewRouter(ct pages.Controller, app core.App, fileFS fs.FS, csrfSecret []byt
6159
pages.EnvelopeDelete(ct, app))
6260
r.Get(routes.EnvelopeHTML(paramID).String(),
6361
pages.EnvelopeHTMLView(ct, app))
64-
r.Delete(routes.EnvelopeList().String(),
65-
pages.EnvelopeListDrop(ct, app))
6662
r.Post(routes.EnvelopeEndpointSend(paramID).String(),
6763
pages.EnvelopeEndpointSend(ct, app))
64+
{
65+
envelopeListView := pages.EnvelopeListView(ct, app)
66+
r.Get(routes.EnvelopeList().String(),
67+
envelopeListView)
68+
r.Delete(routes.EnvelopeList().String(),
69+
pages.EnvelopeListDrop(ct, app, envelopeListView))
70+
}
6871

6972
// Attachment
70-
r.Get(routes.AttachmentList().String(),
71-
pages.AttachmentListView(ct, app))
7273
r.Get(routes.AttachmentFile("*").String(),
7374
pages.Files(ct, app, fileFS))
74-
r.Post(routes.AttachmentTrim().String(),
75-
pages.AttachmentTrim(ct, app))
75+
{
76+
attachmentListView := pages.AttachmentListView(ct, app)
77+
r.Get(routes.AttachmentList().String(),
78+
attachmentListView)
79+
r.Post(routes.AttachmentTrim().String(),
80+
pages.AttachmentTrim(ct, app, attachmentListView))
81+
}
7682

7783
// Endpoint
7884
r.Get(routes.EndpointList().String(),
@@ -81,10 +87,13 @@ func NewRouter(ct pages.Controller, app core.App, fileFS fs.FS, csrfSecret []byt
8187
pages.EndpointTest(ct, app))
8288

8389
// Traces
84-
r.Get(routes.TraceList().String(),
85-
pages.TraceListView(ct, app))
86-
r.Delete(routes.TraceList().String(),
87-
pages.TraceListDrop(ct, app))
90+
{
91+
traceListView := pages.TraceListView(ct, app)
92+
r.Get(routes.TraceList().String(),
93+
traceListView)
94+
r.Delete(routes.TraceList().String(),
95+
pages.TraceListDrop(ct, app, traceListView))
96+
}
8897

8998
// Rules
9099
r.Get(routes.RuleList().String(),

web/pages/envelope.templ

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ templ envelopeListView(m meta.Meta, props envelopeListViewProps) {
9090
</div>
9191
<div class="flex flex-col gap-4 p-4">
9292
<div class="flex flex-col-reverse justify-between gap-4 sm:flex-row">
93-
<form class="join flex">
93+
<form class="join flex" hx-boost="false">
94+
for k := range props.Query {
95+
if k != "search" {
96+
<input type="hidden" name={ k } value={ props.Query.Get(k) } />
97+
}
98+
}
9499
<input name="search" type="text" placeholder="Search" class="input input-sm input-bordered join-item w-full max-w-xs" value={ props.EnvelopeRequestRequest.Search } />
95100
<button type="submit" class="btn btn-sm btn-primary join-item">@icons.Search("w-5 h-5")</button>
96101
</form>

web/pages/envelope_templ.go

+29-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/pages/pages.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func EnvelopeListView(ct Controller, app core.App) http.HandlerFunc {
164164
}
165165
}
166166

167-
func EnvelopeListDrop(ct Controller, app core.App) http.HandlerFunc {
167+
func EnvelopeListDrop(ct Controller, app core.App, view http.Handler) http.HandlerFunc {
168168
return func(w http.ResponseWriter, r *http.Request) {
169169
ctx := r.Context()
170170

@@ -174,7 +174,8 @@ func EnvelopeListDrop(ct Controller, app core.App) http.HandlerFunc {
174174
return
175175
}
176176

177-
htmx.SetRefresh(w)
177+
htmx.SetRetarget(w, "body")
178+
view.ServeHTTP(w, r)
178179
}
179180
}
180181

@@ -471,7 +472,7 @@ func TraceListView(ct Controller, app core.App) http.HandlerFunc {
471472
}
472473
}
473474

474-
func TraceListDrop(ct Controller, app core.App) http.HandlerFunc {
475+
func TraceListDrop(ct Controller, app core.App, view http.Handler) http.HandlerFunc {
475476
return func(w http.ResponseWriter, r *http.Request) {
476477
ctx := r.Context()
477478

@@ -481,7 +482,8 @@ func TraceListDrop(ct Controller, app core.App) http.HandlerFunc {
481482
return
482483
}
483484

484-
htmx.SetRefresh(w)
485+
htmx.SetRetarget(w, "body")
486+
view.ServeHTTP(w, r)
485487
}
486488
}
487489
func RuleListView(ct Controller, app core.App) http.HandlerFunc {
@@ -500,7 +502,7 @@ func RuleListView(ct Controller, app core.App) http.HandlerFunc {
500502
}
501503
}
502504

503-
func AttachmentTrim(ct Controller, app core.App) http.HandlerFunc {
505+
func AttachmentTrim(ct Controller, app core.App, view http.Handler) http.HandlerFunc {
504506
return func(w http.ResponseWriter, r *http.Request) {
505507
ctx := r.Context()
506508
tracer := helpers.Tracer(app, r)
@@ -511,8 +513,8 @@ func AttachmentTrim(ct Controller, app core.App) http.HandlerFunc {
511513
return
512514
}
513515

514-
htmx.SetRefresh(w)
515-
w.WriteHeader(http.StatusOK)
516+
htmx.SetRetarget(w, "body")
517+
view.ServeHTTP(w, r)
516518
}
517519
}
518520

web/pages/rule.templ

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ templ ruleListView(m meta.Meta, props ruleListViewProps) {
3030
</div>
3131
<div class="mx-auto flex flex-col">
3232
for _, rule := range props.Rules {
33-
<div class="hover:bg-base-200 border-base-200 flex items-center justify-between gap-2 border-b first:border-t" hx-target="this" hx-swap="outerHTML">
33+
<div class="hover:bg-base-200 border-base-200 flex items-center justify-between gap-2 border-b first:border-t" id="rule-row">
3434
<a class="flex-1 truncate py-4 pl-4" href={ routes.Rule(rule.ID).URL() }>{ rule.Name }</a>
3535
<div class="flex items-center gap-4 pr-4">
3636
if !rule.Internal {
37-
<button class="btn btn-error btn-sm" hx-delete={ routes.Rule(rule.ID).URLString() } hx-confirm="Are you sure you wish to delete this rule?" >
37+
<button class="btn btn-error btn-sm" hx-delete={ routes.Rule(rule.ID).URLString() } hx-confirm="Are you sure you wish to delete this rule?" hx-target="closest #rule-row" hx-swap="outerHTML">
3838
@icons.Trash("h-4 w-4")
3939
</button>
4040
}

web/pages/rule_templ.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)