Files
openfoodnetwork/app/webpacker/controllers/product_preview_controller.js
Gaetan Craig-Riou 27dd5def57 Open modal before rendering the received html
This way we don't see a blank modal waiting for the content to load
2024-09-10 13:29:39 +10:00

22 lines
668 B
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
connect() {
// open the modal before rendering the html to avoid opening a blank modal
// TODO other option is having a controller in the stream html that would dispatch the open element on connect
window.addEventListener("turbo:before-stream-render", this.#open.bind(this));
}
disconnect() {
window.removeEventListener("turbo:before-stream-render", this.#open.bind(this));
}
// private
#open() {
// dispatch "product-preview:open" event to trigger modal->open action
// see views/admin/product_v3/index.html.haml
this.dispatch("open");
}
}