fix: Stations-on-air widget lagged minutes (timer reset by dbConn object churn)
The 15s poll effect depended on the dbConn OBJECT, which gets a fresh reference on several events — each reset the interval before it fired, so the widget could stay stale for over a minute. Depend on the is-mysql boolean instead, and also refresh ~2s after qso:logged so our own row appears promptly like the ON AIR badge.
This commit is contained in:
+11
-3
@@ -441,13 +441,21 @@ export default function App() {
|
|||||||
type LiveStation = { operator: string; station: string; freq_hz: number; band: string; mode: string; online: boolean; version: string; age_sec: number };
|
type LiveStation = { operator: string; station: string; freq_hz: number; band: string; mode: string; online: boolean; version: string; age_sec: number };
|
||||||
const [liveStations, setLiveStations] = useState<LiveStation[]>([]);
|
const [liveStations, setLiveStations] = useState<LiveStation[]>([]);
|
||||||
const [showLiveStations, setShowLiveStations] = useState(() => localStorage.getItem('opslog.showLiveStations') === '1');
|
const [showLiveStations, setShowLiveStations] = useState(() => localStorage.getItem('opslog.showLiveStations') === '1');
|
||||||
|
// Depend on the BOOLEAN (is-mysql), not the dbConn object: dbConn gets a fresh
|
||||||
|
// reference on several events, and depending on the object reset the 15s timer
|
||||||
|
// on every such refresh so it could ~never fire (the widget looked stuck for
|
||||||
|
// minutes). Also refresh right after we log a QSO so our own row shows without
|
||||||
|
// waiting for the next tick, like the ON AIR badge.
|
||||||
|
const liveStationsOn = dbConn?.backend === 'mysql';
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dbConn?.backend !== 'mysql') { setLiveStations([]); return; }
|
if (!liveStationsOn) { setLiveStations([]); return; }
|
||||||
const load = () => GetLiveStations().then((s) => setLiveStations((s ?? []) as LiveStation[])).catch(() => {});
|
const load = () => GetLiveStations().then((s) => setLiveStations((s ?? []) as LiveStation[])).catch(() => {});
|
||||||
load();
|
load();
|
||||||
const id = window.setInterval(load, 15 * 1000);
|
const id = window.setInterval(load, 15 * 1000);
|
||||||
return () => window.clearInterval(id);
|
// Small delay lets the async publishLiveStatus MySQL write land before we read.
|
||||||
}, [dbConn]);
|
const offLogged = EventsOn('qso:logged', () => { window.setTimeout(load, 2000); });
|
||||||
|
return () => { window.clearInterval(id); offLogged?.(); };
|
||||||
|
}, [liveStationsOn]);
|
||||||
// Mode OpsLog shows when the rig reports generic DIG_U/DIG_L. OmniRig
|
// Mode OpsLog shows when the rig reports generic DIG_U/DIG_L. OmniRig
|
||||||
// can't tell us if it's FT8 vs FT4 vs RTTY, so the user picks the default
|
// can't tell us if it's FT8 vs FT4 vs RTTY, so the user picks the default
|
||||||
// in Preferences > Hardware > CAT interface.
|
// in Preferences > Hardware > CAT interface.
|
||||||
|
|||||||
Reference in New Issue
Block a user