Files
fizzy/app/javascript/controllers/beacon_controller.js
T
Mike Dalessio 8ec109ec1a Delay clearing notifications until a card is actually viewed.
Send the "read" beacon when the card is made visible.

Also take care to only send the "disconnect" beacon if the card is
visible.

ref: https://fizzy.37signals.com/5986089/collections/2/cards/1301
2025-08-08 08:02:54 -04:00

21 lines
382 B
JavaScript

import { post } from "@rails/request.js"
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = { url: String }
visibilityChanged() {
this.#sendBeacon()
}
disconnect() {
this.#sendBeacon()
}
#sendBeacon() {
if (!document.hidden) {
post(this.urlValue, { responseKind: "turbo-stream" })
}
}
}