fix: bug when deleting an award reference which was not saved.
This commit is contained in:
@@ -33,6 +33,19 @@ function appendTokens(existing: string | undefined, refs: string): string {
|
||||
return out;
|
||||
}
|
||||
|
||||
// removeTokens strips space/word-delimited tokens (a "A,B" ref string) from a
|
||||
// text field — the inverse of appendTokens. Used when a picked reference is
|
||||
// REMOVED so an in-field award (DDFM finds "D72" in the note) stops matching it;
|
||||
// otherwise the ref is re-derived from the field and reappears on reopen.
|
||||
function removeTokens(existing: string | undefined, refs: string): string {
|
||||
let out = existing ?? '';
|
||||
for (const tok of refs.split(',').map((s) => s.trim()).filter(Boolean)) {
|
||||
const re = new RegExp(`\\b${tok.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'ig');
|
||||
out = out.replace(re, ' ');
|
||||
}
|
||||
return out.replace(/\s{2,}/g, ' ').trim();
|
||||
}
|
||||
|
||||
// MANUAL_REFS_KEY mirrors award.ManualRefsKey (Go): the ADIF extras key holding
|
||||
// the operator's per-QSO award-reference assignments as "CODE@REF;CODE@REF".
|
||||
// The award engine honours these regardless of how the award matches, so a
|
||||
@@ -47,8 +60,24 @@ const MANUAL_REFS_KEY = 'APP_OPSLOG_AWARDREFS';
|
||||
// data lives in its conventional place and exports correctly. Awards that match
|
||||
// a free-text field by description/pattern (address/qth/name/custom) rely solely
|
||||
// on the override — we don't pollute the text field with a code.
|
||||
export function applyAwardRefs(payload: any, awardRefs: string, fieldOf: Record<string, string>) {
|
||||
export function applyAwardRefs(payload: any, awardRefs: string, fieldOf: Record<string, string>, prevAwardRefs?: string) {
|
||||
const byCode = parseAwardRefs(awardRefs);
|
||||
// References the operator REMOVED since the editor opened: for in-field awards
|
||||
// (note/comment) strip the token from the field too, so a deleted DDFM/etc.
|
||||
// ref doesn't get re-derived from the leftover token and reappear on reopen.
|
||||
if (prevAwardRefs != null) {
|
||||
const prev = parseAwardRefs(prevAwardRefs);
|
||||
for (const [code, prevRef] of Object.entries(prev)) {
|
||||
const field = fieldOf[code] || code.toLowerCase();
|
||||
if (field !== 'note' && field !== 'notes' && field !== 'comment') continue;
|
||||
const now = new Set((byCode[code] ?? '').split(',').map((s) => s.trim().toUpperCase()).filter(Boolean));
|
||||
const removed = prevRef.split(',').map((s) => s.trim()).filter(Boolean).filter((r) => !now.has(r.toUpperCase()));
|
||||
if (removed.length === 0) continue;
|
||||
const rm = removed.join(',');
|
||||
if (field === 'comment') payload.comment = removeTokens(payload.comment, rm);
|
||||
else payload.notes = removeTokens(payload.notes, rm);
|
||||
}
|
||||
}
|
||||
const extras: Record<string, string> = { ...(payload.extras ?? {}) };
|
||||
const overrides: string[] = [];
|
||||
for (const [code, ref] of Object.entries(byCode)) {
|
||||
|
||||
Reference in New Issue
Block a user