// The station's own rigs and antennas, for the MY_RIG and MY_ANTENNA fields. // // They are already defined once, in Settings ▸ Operating conditions — a station // per rig, with the antennas hanging off it. Typing them again into every // contact is both work and a source of spellings that do not match: "IC-7610", // "IC 7610" and "ic7610" are three different rigs to an award, a filter and to // anyone reading the log later. // // So the two fields offer what the operator has already declared. FREE TEXT // stays allowed: a QSO made from somebody else's station, or imported from // another logger, carries a rig that was never in this tree and must still be // loggable — the same rule the satellite-name field follows. import { useEffect, useState } from 'react'; import { ListOperatingTree } from '../../wailsjs/go/main/App'; export type OperatingLists = { rigs: string[]; // Every antenna in the profile, whichever rig it belongs to. antennas: string[]; // The antennas of ONE rig. Falls back to all of them for a rig that is not in // the tree — an operator typing a borrowed rig's name should still be offered // their own antennas rather than nothing. antennasFor: (rig: string) => string[]; }; const EMPTY: OperatingLists = { rigs: [], antennas: [], antennasFor: () => [] }; function build(stations: any[]): OperatingLists { const rigs: string[] = []; const byRig = new Map(); const all = new Set(); for (const st of stations ?? []) { const name = String(st?.name ?? '').trim(); const ants = ((st?.antennas ?? []) as any[]) .map((a) => String(a?.name ?? '').trim()) .filter(Boolean); if (name) { rigs.push(name); byRig.set(name.toUpperCase(), ants); } for (const a of ants) all.add(a); } const antennas = [...all]; return { rigs, antennas, antennasFor: (rig: string) => byRig.get(String(rig ?? '').trim().toUpperCase()) ?? antennas, }; } // useOperatingLists reads the tree when the component mounts, and again whenever // `reloadKey` changes — pass something that moves when Preferences close, so a // rig added there is offered without a restart. export function useOperatingLists(reloadKey?: unknown): OperatingLists { const [lists, setLists] = useState(EMPTY); useEffect(() => { let live = true; ListOperatingTree() .then((st: any) => { if (live) setLists(build(st ?? [])); }) // An empty list simply leaves both fields as free text, which is what they // were before they had a list at all. .catch(() => {}); return () => { live = false; }; }, [reloadKey]); return lists; }