This commit is contained in:
2026-06-07 01:11:37 +02:00
parent 17f7a00bd7
commit 16c04fc12b
13 changed files with 418 additions and 52 deletions
+20 -5
View File
@@ -15,7 +15,7 @@ type Meta = { code: string; count: number; can_update: boolean };
// never picked. NB: 'state' and 'cnty' are NOT here — they're operator-settable
// QSO fields driving predefined-list awards (WAS/RAC/WAJA/JCC), so they ARE
// pickable (a lookup rarely fills the JA prefecture or VE province).
const COMPUTED_FIELDS = new Set(['dxcc', 'cqz', 'ituz', 'prefix', 'callsign', 'cont', 'country', 'grid']);
const COMPUTED_FIELDS = new Set(['dxcc', 'cqz', 'ituz', 'prefix', 'callsign', 'cont', 'country', 'grid', 'grid4']);
// If DXCC-filtered auto-results exceed this, require the user to type instead.
const AUTO_SHOW_MAX = 100;
@@ -86,15 +86,30 @@ export function AwardRefSelector({ dxcc, value, onChange }: Props) {
// For dynamic lists, restrict to the contacted entity; otherwise load all.
const refDxcc = isDynamic ? (dxcc ?? 0) : 0;
// Search helper with a DXCC fallback: try the entity-scoped query first, but
// if it finds nothing AND we were filtering by DXCC, retry unfiltered. This
// fixes awards whose references carry no per-ref DXCC (e.g. SOTA summits,
// where the country is in the summit prefix F/AB-001, not a DXCC column) —
// otherwise filtering by entity returns zero. POTA/IOTA keep entity filtering
// when their refs do match.
const searchRefs = async (query: string, limit: number): Promise<AwardRef[]> => {
let r = (await SearchAwardReferences(awardCode, query, refDxcc, limit)) as any as AwardRef[];
if ((!r || r.length === 0) && refDxcc > 0) {
r = (await SearchAwardReferences(awardCode, query, 0, limit)) as any as AwardRef[];
}
return r ?? [];
};
// Auto-load refs on award/dxcc change with empty query. Fetches AUTO_SHOW_MAX+1
// so we can distinguish "all results shown" from "too many to list".
useEffect(() => {
setAutoResults([]);
// Dynamic lists need an entity to scope to; predefined lists load regardless.
if (isDynamic && !dxcc) return;
SearchAwardReferences(awardCode, '', refDxcc, AUTO_SHOW_MAX + 1)
.then((r) => setAutoResults((r ?? []) as any))
searchRefs('', AUTO_SHOW_MAX + 1)
.then((r) => setAutoResults(r))
.catch(() => {});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [awardCode, dxcc, isDynamic, refDxcc]);
// Typed search (2+ chars).
@@ -103,12 +118,12 @@ export function AwardRefSelector({ dxcc, value, onChange }: Props) {
const t = window.setTimeout(async () => {
setBusy(true);
try {
const r = await SearchAwardReferences(awardCode, q, refDxcc, 50);
setSearchResults((r ?? []) as any);
setSearchResults(await searchRefs(q, 50));
} catch { setSearchResults([]); }
finally { setBusy(false); }
}, 200);
return () => window.clearTimeout(t);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [awardCode, q, refDxcc]);
const tooManyAuto = autoResults.length > AUTO_SHOW_MAX;