Files
fizzy/app/javascript/controllers/frame_reloader_controller.js
Jorge Manrubia 6269f3c47e Reload notifications tray when the window regain the focus
https://app.fizzy.do/5986089/cards/2743

It includes a debounce interval to avoid too many of these.
2025-11-18 08:49:19 +01:00

22 lines
462 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = {
reloadInterval: { type: Number, default: 10 * 60 } // 10 minutes
}
connect() {
this.freshSince = Date.now()
}
reload() {
const now = Date.now()
const reloadIntervalMs = this.reloadIntervalValue * 1000
if ((now - this.freshSince) >= reloadIntervalMs) {
this.freshSince = now
this.element.reload()
}
}
}