Global refresh rate in Settings drives every live view and each machine's sampler; per-page pickers removed
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
a4f39859b6
commit
bbf0f2580f
@@ -0,0 +1,32 @@
|
||||
// Global refresh rate: one setting for every live view. Kept in localStorage for instant
|
||||
// use and mirrored to the hub's UI prefs so it follows the login.
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export const REFRESH_OPTIONS = [250, 500, 1000, 2000, 5000] as const
|
||||
export const DEFAULT_REFRESH = 2000
|
||||
// Lists that shell out on the host (services, cron, updates, machines) never poll faster than this.
|
||||
export const LIST_FLOOR = 2000
|
||||
const KEY = 'hamlab.refresh'
|
||||
|
||||
export function getRefreshMs(): number {
|
||||
const v = Number(localStorage.getItem(KEY))
|
||||
return v >= 100 && v <= 60000 ? v : DEFAULT_REFRESH
|
||||
}
|
||||
|
||||
export function setRefreshMs(ms: number) {
|
||||
localStorage.setItem(KEY, String(ms))
|
||||
window.dispatchEvent(new CustomEvent('hamlab:refresh', { detail: ms }))
|
||||
}
|
||||
|
||||
export function fmtMs(ms: number): string { return ms >= 1000 ? `${ms / 1000} s` : `${ms} ms` }
|
||||
|
||||
// useRefreshMs re-renders the caller when the global rate changes.
|
||||
export function useRefreshMs(floor = 0): number {
|
||||
const [ms, setMs] = useState(getRefreshMs())
|
||||
useEffect(() => {
|
||||
const h = (e: Event) => setMs((e as CustomEvent<number>).detail)
|
||||
window.addEventListener('hamlab:refresh', h)
|
||||
return () => window.removeEventListener('hamlab:refresh', h)
|
||||
}, [])
|
||||
return Math.max(ms, floor)
|
||||
}
|
||||
Reference in New Issue
Block a user