diff --git a/frontend/src/components/BandMap.tsx b/frontend/src/components/BandMap.tsx index 65cd787..fa23637 100644 --- a/frontend/src/components/BandMap.tsx +++ b/frontend/src/components/BandMap.tsx @@ -151,7 +151,7 @@ export function BandMap({ band, spots, spotStatus, currentFreqHz, onSpotClick, o const { t } = useI18n(); const range = BAND_RANGES[band]; const segments = SEGMENT_COLORS[band] ?? []; - const [zoomIdx, setZoomIdx] = useState(0); + const [zoomIdx, setZoomIdx] = useState(2); // default 32 px/kHz const scrollerRef = useRef(null); const [containerH, setContainerH] = useState(400); @@ -284,36 +284,19 @@ export function BandMap({ band, spots, spotStatus, currentFreqHz, onSpotClick, o const innerH = Math.max(containerH - TOP_PAD - BOT_PAD, span * pxPerKHz); const freqToY = (kHz: number) => TOP_PAD + (1 - (kHz - lo) / span) * innerH; - // Auto-centre on the rig frequency when the map opens or the band changes - // (once per band, so it doesn't fight the user's manual scrolling). Waits - // for the scroller height to be measured and a valid in-band rig freq. - const centeredForRef = useRef(''); + // Keep the map centred on the rig frequency: the effect re-runs only when the + // frequency actually changes (or band/zoom/size), so tuning follows the rig + // while a stable frequency leaves your manual scroll alone. useEffect(() => { if (!range || containerH <= 0 || currentFreqHz <= 0) return; const kHz = currentFreqHz / 1000; if (kHz < lo || kHz > hi) return; - if (centeredForRef.current === band) return; const el = scrollerRef.current; if (!el) return; - centeredForRef.current = band; el.scrollTop = Math.max(0, freqToY(kHz) - containerH / 2); // freqToY is recomputed each render; intentionally excluded from deps. // eslint-disable-next-line react-hooks/exhaustive-deps - }, [band, containerH, currentFreqHz, range, lo, hi]); - - // Re-centre on the rig frequency whenever the zoom level changes — zooming - // would otherwise drift away from where you're operating. Skips the initial - // mount (the band-centre effect above handles that). - const firstZoomRef = useRef(true); - useEffect(() => { - if (firstZoomRef.current) { firstZoomRef.current = false; return; } - const el = scrollerRef.current; - if (!el || !range || containerH <= 0) return; - const kHz = currentFreqHz && currentFreqHz / 1000 >= lo && currentFreqHz / 1000 <= hi - ? currentFreqHz / 1000 : (lo + hi) / 2; - el.scrollTop = Math.max(0, freqToY(kHz) - containerH / 2); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [zoomIdx]); + }, [band, containerH, currentFreqHz, range, lo, hi, pxPerKHz]); useEffect(() => { const el = scrollerRef.current; @@ -365,16 +348,16 @@ export function BandMap({ band, spots, spotStatus, currentFreqHz, onSpotClick, o return (
-
- {t('bmp.map')} · {band} +
+ {t('bmp.map')} · {band} - {pxPerKHz}px/kHz + {pxPerKHz}px/kHz