feat: Contest mode added

This commit is contained in:
2026-07-04 22:54:41 +02:00
parent dd4b0004a5
commit e590a58702
8 changed files with 292 additions and 7 deletions
+56 -6
View File
@@ -68,6 +68,7 @@ import { ClusterGrid } from '@/components/ClusterGrid';
import { cleanSpotter, inferSpotMode, spotModeCategory, spotStatusKey } from '@/lib/spot';
import { WorkedBeforeGrid } from '@/components/WorkedBeforeGrid';
import { NetControlPanel } from '@/components/NetControlPanel';
import { ContestBar, CONTEST_DEFAULT, type ContestSession } from '@/components/ContestBar';
import { AlertsModal } from '@/components/AlertsModal';
import { BulkEditModal } from '@/components/BulkEditModal';
import { ChatPanel, type ChatMsg, type ChatPresence } from '@/components/ChatPopover';
@@ -339,6 +340,11 @@ export default function App() {
const [grid, setGrid] = useState('');
const [name, setName] = useState('');
const [qth, setQth] = useState('');
// Contest mode: a picked contest + exchange config; persisted so a running
// contest (serial counter included) survives a restart. `rcv` is the received
// exchange for the current QSO.
const [contest, setContest] = useState<ContestSession>(CONTEST_DEFAULT);
const [rcv, setRcv] = useState('');
const [country, setCountry] = useState('');
const [comment, setComment] = useState('');
const [note, setNote] = useState('');
@@ -576,6 +582,20 @@ export default function App() {
});
useEffect(() => { writeUiPref('hamlog.qsoLimit', String(qsoLimit)); }, [qsoLimit]);
// Contest session: load once, then persist on every change (merge + save).
useEffect(() => {
GetUIPref('opslog.contest').then((s) => {
if (s) { try { setContest({ ...CONTEST_DEFAULT, ...JSON.parse(s) }); } catch {} }
}).catch(() => {});
}, []);
const updateContest = (patch: Partial<ContestSession>) => {
setContest((c) => {
const next = { ...c, ...patch };
writeUiPref('opslog.contest', JSON.stringify(next));
return next;
});
};
// === DX Cluster live state ===
type ClusterSpot = {
source_id: number;
@@ -1833,7 +1853,23 @@ export default function App() {
email: details.email,
};
applyAwardRefs(payload, details.award_refs ?? '', awardFieldRef.current);
// Contest mode overrides the exchange fields: CONTEST_ID, the sent
// exchange (running serial or fixed value) and the received exchange.
if (contest.active && contest.code) {
const sent = contest.exchange === 'serial' ? String(contest.nextSerial) : contest.sentFixed;
const sE = exchangeFields(sent);
const rE = exchangeFields(rcv.trim());
Object.assign(payload, {
contest_id: contest.code,
stx: sE.num, stx_string: sE.str,
srx: rE.num, srx_string: rE.str,
});
}
await AddQSO(payload);
// Advance the sent serial only after a successful log.
if (contest.active && contest.code && contest.exchange === 'serial') {
updateContest({ nextSerial: contest.nextSerial + 1 });
}
resetEntry(); // clears the call AND the Worked-before matrix
callsignRef.current?.focus(); // return focus to the call field, wherever it was (e.g. Name)
await refresh();
@@ -1849,7 +1885,7 @@ export default function App() {
// Discard any in-progress QSO recording (no-op if it was already saved on
// log, or if the recorder is off).
QSOAudioCancel(); setRecording(false); recordingCallRef.current = "";
setCallsign(''); setComment(''); setNote('');
setCallsign(''); setComment(''); setNote(''); setRcv('');
if (!locks.start) setQsoStartedAt(null);
if (!locks.end) setQsoEndedAt(null);
resetAutoFill();
@@ -2539,7 +2575,22 @@ export default function App() {
<Input value={name} onChange={(e) => { setName(e.target.value); markEdited('name'); }} />
</div>
);
const qthBlock = (
// In contest mode QTH is replaced by the sent (read-only, auto) and received
// exchange fields — the exchange is what matters, not the town.
const contestSnt = contest.exchange === 'serial'
? String(contest.nextSerial).padStart(3, '0')
: (contest.sentFixed || '—');
const qthBlock = contest.active ? (
<>
<div className="flex flex-col w-16 shrink-0"><Label className="mb-1 h-3.5">Snt</Label>
<Input readOnly tabIndex={-1} value={contestSnt} className="font-mono bg-muted/40" />
</div>
<div className="flex flex-col w-24 shrink-0"><Label className="mb-1 h-3.5 text-amber-600 font-bold">Rcv</Label>
<Input value={rcv} placeholder="exch" className="font-mono"
onChange={(e) => setRcv(e.target.value.toUpperCase())} />
</div>
</>
) : (
<div className="flex flex-col flex-[0.55] min-w-[70px]"><Label className="mb-1 h-3.5">QTH</Label>
<Input value={qth} onChange={(e) => { setQth(e.target.value); markEdited('qth'); }} />
</div>
@@ -2602,7 +2653,7 @@ export default function App() {
// CQ/ITU zones moved to the Info (F2) tab (DetailsPanel).
const freqBlock = (
<div className="flex flex-col w-32">
<Label className="mb-1 h-3.5 flex items-center gap-1">{catState.split ? 'TX Freq (MHz)' : 'Freq (MHz)'} <LockBtn k="freq" title="frequency" /></Label>
<Label className="mb-1 h-3.5 flex items-center gap-1">TX Freq (MHz) <LockBtn k="freq" title="frequency" /></Label>
<Input
tabIndex={-1}
className="font-mono"
@@ -3423,9 +3474,7 @@ export default function App() {
<div className="flex flex-col w-[300px] shrink-0"><Label className="mb-1 h-3.5">Name</Label>
<Input value={name} onChange={(e) => { setName(e.target.value); markEdited('name'); }} />
</div>
<div className="flex flex-col flex-1 min-w-[70px]"><Label className="mb-1 h-3.5">QTH</Label>
<Input value={qth} onChange={(e) => { setQth(e.target.value); markEdited('qth'); }} />
</div>
{qthBlock}
{gridBlock}
</div>
@@ -3638,6 +3687,7 @@ export default function App() {
{/* ===== LOWER: tabbed table / cluster / band map ===== */}
{compact ? null : <>
<ContestBar session={contest} onChange={updateContest} />
<div className={cn('grid gap-2.5 p-2.5 flex-1 min-h-0 grid-rows-[minmax(0,1fr)]',
showBandMap ? (bandMapSide === 'left' ? 'grid-cols-[300px_1fr]' : 'grid-cols-[1fr_300px]') : 'grid-cols-[1fr]')}>
<section className="bg-card border border-border rounded-lg shadow-sm flex flex-col min-h-0 overflow-hidden">
+115
View File
@@ -0,0 +1,115 @@
import { useEffect, useState } from 'react';
import { ListContests } from '../../wailsjs/go/main/App';
import { cn } from '@/lib/utils';
// ContestSession is the live contest-mode state, persisted as JSON in a UI pref
// so a running contest survives a restart (serial counter included).
export type ContestSession = {
active: boolean;
code: string; // ADIF CONTEST_ID written to each QSO
name: string; // display name
exchange: 'serial' | 'fixed';
fixedKind: string; // label for the fixed exchange (CQ Zone, Département…)
sentFixed: string; // the value YOU send when the exchange is fixed
nextSerial: number; // running sent serial number
};
export const CONTEST_DEFAULT: ContestSession = {
active: false, code: '', name: '', exchange: 'serial',
fixedKind: 'CQ Zone', sentFixed: '', nextSerial: 1,
};
const FIXED_KINDS = ['CQ Zone', 'ITU Zone', 'State/Prov', 'Département', 'Grid', 'Name', 'Age', 'Section', 'Custom'];
// Map the catalogue's default exchange hint onto a fixed-kind label.
const KIND_LABEL: Record<string, string> = {
'cq-zone': 'CQ Zone', 'itu-zone': 'ITU Zone', 'state': 'State/Prov',
'dept': 'Département', 'grid': 'Grid', 'name': 'Name', 'class-section': 'Section',
};
type Def = { code: string; name: string; exchange: string };
export function ContestBar({ session, onChange }: {
session: ContestSession;
onChange: (patch: Partial<ContestSession>) => void;
}) {
const [contests, setContests] = useState<Def[]>([]);
useEffect(() => { ListContests().then((c) => setContests((c ?? []) as Def[])).catch(() => {}); }, []);
const pickContest = (code: string) => {
const def = contests.find((c) => c.code === code);
if (!def) { onChange({ code: '', name: '' }); return; }
if (def.exchange === 'serial' || def.exchange === 'rst') {
onChange({ code: def.code, name: def.name, exchange: 'serial' });
} else {
onChange({ code: def.code, name: def.name, exchange: 'fixed', fixedKind: KIND_LABEL[def.exchange] || 'Custom' });
}
};
if (!session.active) {
return (
<div className="flex items-center px-3 py-1.5">
<button type="button" onClick={() => onChange({ active: true })}
className="rounded-md border border-border bg-card px-2.5 py-1 text-xs font-bold text-muted-foreground hover:bg-muted">
Contest mode
</button>
</div>
);
}
const snt = session.exchange === 'serial'
? String(session.nextSerial).padStart(3, '0')
: (session.sentFixed || '—');
return (
<div className="flex items-center gap-2 px-3 py-1.5 border-y-2 border-amber-500 bg-amber-500/10 flex-wrap">
<span className="rounded bg-amber-500 px-2 py-0.5 text-[11px] font-black uppercase tracking-wider text-white shrink-0">
Contest
</span>
<select value={session.code} onChange={(e) => pickContest(e.target.value)}
className="rounded-md border border-border bg-card px-2 py-1 text-xs max-w-[260px]">
<option value=""> pick contest </option>
{contests.map((c) => <option key={c.code} value={c.code}>{c.name}</option>)}
</select>
{session.code && <span className="text-[11px] font-mono text-muted-foreground shrink-0">{session.code}</span>}
{/* Serial vs fixed exchange. */}
<div className="inline-flex rounded-md border border-border overflow-hidden shrink-0">
{(['serial', 'fixed'] as const).map((x) => (
<button key={x} type="button" onClick={() => onChange({ exchange: x })}
className={cn('px-2 py-1 text-[11px] font-bold border-l border-border first:border-l-0',
session.exchange === x ? 'bg-primary text-primary-foreground' : 'bg-card text-muted-foreground hover:bg-muted')}>
{x === 'serial' ? 'Serial' : 'Fixed'}
</button>
))}
</div>
{session.exchange === 'serial' ? (
<label className="flex items-center gap-1 text-[11px] text-muted-foreground shrink-0">
Next#
<input type="number" min={1} value={session.nextSerial}
onChange={(e) => onChange({ nextSerial: Math.max(1, parseInt(e.target.value || '1', 10)) })}
className="w-16 rounded-md border border-border bg-card px-1.5 py-1 text-xs font-mono" />
</label>
) : (
<div className="flex items-center gap-2 shrink-0">
<select value={session.fixedKind} onChange={(e) => onChange({ fixedKind: e.target.value })}
className="rounded-md border border-border bg-card px-2 py-1 text-xs">
{FIXED_KINDS.map((k) => <option key={k} value={k}>{k}</option>)}
</select>
<input value={session.sentFixed} onChange={(e) => onChange({ sentFixed: e.target.value.toUpperCase() })}
placeholder="your exch" className="w-24 rounded-md border border-border bg-card px-2 py-1 text-xs font-mono" />
</div>
)}
<span className="text-[11px] text-muted-foreground shrink-0">
Snt <b className="font-mono text-foreground">{snt}</b>
</span>
<button type="button" onClick={() => onChange({ active: false })}
className="ml-auto rounded-md border border-border bg-card px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted shrink-0">
Exit
</button>
</div>
);
}
+1 -1
View File
@@ -426,7 +426,7 @@ export function QSOEditModal({ qso, onSave, onDelete, onClose, countries = [], b
{flagURL(draft.dxcc) && <img src={flagURL(draft.dxcc)} alt="" className="h-4 rounded-[2px] border border-border/50" referrerPolicy="no-referrer" />}
</div>
<div className="flex items-center gap-2">
<Label className="w-20 shrink-0">Freq</Label>
<Label className="w-20 shrink-0">TX Freq</Label>
<Input value={freqKHz} onChange={(e) => setFreqKHz(e.target.value.replace(/\D/g, ''))} className="font-mono w-24" placeholder="kHz" />
<Input value={freqHz} onChange={(e) => setFreqHz(e.target.value.replace(/\D/g, ''))} maxLength={3} className="font-mono w-16" placeholder="Hz" />
</div>