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:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user