fix: Added LOTW badge for Lotw users colored depending on their last upload

This commit is contained in:
2026-07-09 19:32:32 +02:00
parent f3bf0b2f5c
commit 16e780c2df
13 changed files with 465 additions and 6 deletions
+32
View File
@@ -27,6 +27,7 @@ import {
ListClusterServers, ClusterSpotStatuses, SendClusterSpot,
GetCATSettings,
GetSolarData,
LoTWUserInfo,
OperatingDefaultForBand,
LogUDPLoggedADIF,
ListCountries,
@@ -383,6 +384,19 @@ export default function App() {
const id = window.setInterval(load, 60 * 60 * 1000); // hourly fallback; the event refreshes it live
return () => { off(); window.clearInterval(id); };
}, []);
// LoTW-user lookup for the entered callsign (from the cached ARRL activity list),
// debounced. Drives a colour-coded LoTW badge by last-upload recency.
const [lotwInfo, setLotwInfo] = useState<{ is_user: boolean; last_upload?: string; days_ago: number } | null>(null);
useEffect(() => {
const c = callsign.trim();
if (!c) { setLotwInfo(null); return; }
const run = () => { LoTWUserInfo(c).then((r) => setLotwInfo(r as any)).catch(() => setLotwInfo(null)); };
const t = window.setTimeout(run, 300);
// Re-run when the background auto-download finishes (so a call typed before
// the list loaded gets its badge without re-typing).
const off = EventsOn('lotwusers:updated', run);
return () => { window.clearTimeout(t); off(); };
}, [callsign]);
const [rotatorHeading, setRotatorHeading] = useState<{ enabled: boolean; ok: boolean; azimuth: number }>({ enabled: false, ok: false, azimuth: 0 });
const [ubStatus, setUbStatus] = useState<{ enabled: boolean; connected: boolean; direction: number; moving: boolean }>({ enabled: false, connected: false, direction: 0, moving: false });
const [agStatus, setAgStatus] = useState<AGStatus>({ connected: false, port_a: 0, port_b: 0, antennas: [] });
@@ -2743,6 +2757,23 @@ export default function App() {
<Input value={grid} placeholder="JN05" className="font-mono" onChange={(e) => { setGrid(e.target.value); markEdited('grid'); }} />
</div>
);
// LoTW-user badge: shown only when the entered call is a LoTW user, coloured by
// last-upload recency (green < 1 week · amber 14 weeks · red > 30 days). The
// tooltip shows the exact last-upload date. Needs the list downloaded once
// (Settings → LoTW); until then no badge appears.
const lotwBlock = (lotwInfo && lotwInfo.is_user) ? (() => {
const d = lotwInfo.days_ago ?? -1;
const cls = d >= 0 && d < 7 ? 'border-success text-success bg-success/15'
: d < 30 ? 'border-warning text-warning bg-warning/15'
: 'border-danger text-danger bg-danger/15';
return (
<div className="self-end shrink-0" title={t('lotw.userTip', { date: lotwInfo.last_upload || '?', days: d })}>
<span className={cn('inline-flex items-center rounded-md border px-1.5 py-1.5 text-[10px] font-extrabold tracking-wide leading-none', cls)}>
LoTW
</span>
</div>
);
})() : null;
// A discreet spot-alert LED (bell) that fills the gap at the right of the Grid
// row instead of the intrusive floating cards. It lights + shows a count when
// alerts are pending; click it to see the last 3 (each clickable to tune).
@@ -3706,6 +3737,7 @@ export default function App() {
</div>
{qthBlock}
{gridBlock}
{lotwBlock}
{alertLedBlock}
</div>