Files
fizzy/app/javascript/controllers/frame_controller.js
T
Jorge Manrubia 85b9e3dfd4 Make the notifications tray reload on broadcasted refreshes
We can't use the normal refresh: :morph because everything is contained in a turbo permanent section
so that the trays persist across regular navigation.
2025-11-21 09:41:03 +01:00

23 lines
587 B
JavaScript

import { Controller } from "@hotwired/stimulus"
import { Turbo } from "@hotwired/turbo-rails"
export default class extends Controller {
morphRender({ detail }) {
detail.render = function (currentElement, newElement) {
Turbo.morphChildren(currentElement, newElement)
}
}
morphReload(event) {
const newElement = event.detail.newElement
if (newElement && newElement.tagName === "TURBO-FRAME" && newElement.matches('[data-controller~="frame"]')) {
event.preventDefault()
this.element.reload()
}
}
reload() {
this.element.reload()
}
}