Aggiorna lo stato dell'invio email senza ricaricare la pagina.
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled

Così la lista destinatari si aggiorna in corso d'opera senza riportare lo scroll in cima.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 23:03:35 +02:00
co-authored by Cursor
parent a33a281a96
commit 4e03fa58ab
4 changed files with 54 additions and 8 deletions
@@ -4,17 +4,46 @@ export default class extends Controller {
static values = { interval: { type: Number, default: 10000 } }
connect() {
this.timer = setInterval(() => {
if (document.hidden) return
if (window.Turbo?.visit) {
window.Turbo.visit(window.location.href, { action: "replace" })
} else {
window.location.reload()
}
}, this.intervalValue)
this.timer = setInterval(() => this.refresh(), this.intervalValue)
}
disconnect() {
clearInterval(this.timer)
}
refresh() {
if (document.hidden) return
const frame = this.element.closest("turbo-frame")
if (frame && typeof frame.reload === "function") {
this.reloadFrame(frame)
return
}
this.refreshPreservingScroll()
}
reloadFrame(frame) {
if (frame.hasAttribute("busy")) return
const url = window.location.href
if (frame.getAttribute("src") === url) {
frame.reload()
} else {
frame.setAttribute("src", url)
}
}
refreshPreservingScroll() {
const { scrollX, scrollY } = window
const restore = () => window.scrollTo(scrollX, scrollY)
document.addEventListener("turbo:render", restore, { once: true })
document.addEventListener("turbo:load", restore, { once: true })
if (window.Turbo?.visit) {
window.Turbo.visit(window.location.href, { action: "replace" })
} else {
window.location.reload()
}
}
}
+2
View File
@@ -1,4 +1,5 @@
<% refresh = @active_mailings.any? %>
<%= turbo_frame_tag "mailings_dashboard_live", target: "_top", refresh: "morph" do %>
<%= tag.div class: "space-y-6", data: (refresh ? { controller: "auto-reload", auto_reload_interval_value: 10_000 } : {}) do %>
<div class="flex flex-wrap items-end justify-between gap-3">
<div>
@@ -135,3 +136,4 @@
<% end %>
</div>
<% end %>
<% end %>
+2
View File
@@ -1,3 +1,4 @@
<%= turbo_frame_tag "mailing_live", target: "_top", refresh: "morph" do %>
<%= tag.div class: "space-y-6", data: (@mailing.sending? ? { controller: "auto-reload", auto_reload_interval_value: 10_000 } : {}) do %>
<div class="flex flex-wrap items-start justify-between gap-3">
<div class="min-w-0">
@@ -280,3 +281,4 @@
</section>
</div>
<% end %>
<% end %>