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.
This commit is contained in:
Jorge Manrubia
2025-11-17 13:38:15 +01:00
parent d8f935498a
commit 6269f3c47e
3 changed files with 26 additions and 2 deletions
@@ -0,0 +1,21 @@
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()
}
}
}