Skip to content

Commit

Permalink
Change reject suggestion behavior to htmx replace #1669
Browse files Browse the repository at this point in the history
  • Loading branch information
verheyenkoen committed Sep 16, 2024
1 parent acbc2ae commit ce6658e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 36 deletions.
13 changes: 11 additions & 2 deletions handlers/candidaterecords/candidate_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,19 @@ func RejectCandidateRecord(w http.ResponseWriter, r *http.Request) {
f := flash.SimpleFlash().
WithLevel("success").
WithBody("<p>Candidate record was successfully deleted.</p>")
c.Flash = append(c.Flash, *f)

c.PersistFlash(w, *f)
rec, err = c.Repo.GetCandidateRecord(r.Context(), rec.ID)
if err != nil {
c.HandleError(w, r, err)
return
}

w.Header().Set("HX-Redirect", c.URLTo("candidate_records").String())
views.Cat(
candidaterecordviews.ListItem(c, rec),
views.CloseModal(),
views.Replace("#flash-messages", views.FlashMessages(c)),
).Render(r.Context(), w)
}

func ImportCandidateRecord(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 3 additions & 1 deletion views/candidaterecord/confirm_hide.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package candidaterecordviews

import (
"fmt"
"github.com/ugent-library/biblio-backoffice/ctx"
"github.com/ugent-library/biblio-backoffice/models"
)
Expand All @@ -27,7 +28,8 @@ templ ConfirmHide(c *ctx.Ctx, rec *models.CandidateRecord) {
<button
class="btn btn-danger"
hx-put={ c.PathTo("reject_candidate_record", "id", rec.ID).String() }
hx-swap="none"
hx-target={ fmt.Sprintf("#candidate-record-%s", rec.ID) }
hx-swap="outerHTML"
>Yes, reject suggestion</button>
</div>
</div>
Expand Down
18 changes: 16 additions & 2 deletions views/candidaterecord/confirm_hide_templ.go

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

14 changes: 7 additions & 7 deletions views/replace.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ templ Replace(selector string, component templ.Component) {
}

templ ReplaceModal(component templ.Component) {
<div hx-swap-oob="innerHTML:#modal">
@component
</div>
@Replace("#modal", component)
}

templ CloseModalAndReplace(selector string, component templ.Component) {
templ CloseModal() {
<div hx-swap-oob="innerHTML:#modals"></div>
<div hx-swap-oob={ fmt.Sprintf("innerHTML:%s", selector) }>
@component
</div>
}

templ CloseModalAndReplace(selector string, component templ.Component) {
@CloseModal()
@Replace(selector, component)
}
49 changes: 25 additions & 24 deletions views/replace_templ.go

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

0 comments on commit ce6658e

Please sign in to comment.