WIP on htmx 4; user messages now work (#60)
This commit is contained in:
@@ -442,22 +442,21 @@ this.Admin = {
|
||||
}
|
||||
}
|
||||
|
||||
htmx.on("htmx:afterOnLoad", function (evt) {
|
||||
const hdrs = evt.detail.xhr.getAllResponseHeaders()
|
||||
htmx.on("htmx:after:swap", function (evt) {
|
||||
// Initialize any toasts that were pre-rendered from the server
|
||||
Admin.showPreRenderedMessages()
|
||||
// Show messages if there were any in the response
|
||||
if (hdrs.indexOf("x-message") >= 0) {
|
||||
Admin.showMessage(evt.detail.xhr.getResponseHeader("x-message"))
|
||||
const hdrs = evt.detail.ctx.response.headers
|
||||
if (hdrs.has("x-message")) {
|
||||
hdrs.get("x-message").split(", ").forEach(Admin.showMessage)
|
||||
}
|
||||
})
|
||||
|
||||
htmx.on("htmx:responseError", function (evt) {
|
||||
const xhr = evt.detail.xhr
|
||||
const hdrs = xhr.getAllResponseHeaders()
|
||||
htmx.on("htmx:response:error", function (evt) {
|
||||
const resp = evt.detail.ctx.response
|
||||
// Show an error message if there were none in the response
|
||||
if (hdrs.indexOf("x-message") < 0) {
|
||||
Admin.showMessage(`danger|||${xhr.status}: ${xhr.statusText}`)
|
||||
if (!resp.headers.has("x-message")) {
|
||||
Admin.showMessage(`danger|||${resp.status}: ${resp.statusText}`)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user