diff --git a/client/src/components/LiveLogView.tsx b/client/src/components/LiveLogView.tsx index 68670e4..ac1e4f5 100644 --- a/client/src/components/LiveLogView.tsx +++ b/client/src/components/LiveLogView.tsx @@ -73,6 +73,7 @@ import { type GeolocationErrorReason, type GpsSignalQuality } from '../utils/geolocation.js' +import { formatCourseAngle } from '../utils/courseAngle.js' import { sortLogEventsByTime, type LogEventPayload } from '../utils/logEntryPayload.js' import { dedupeSailNames, @@ -633,16 +634,18 @@ export default function LiveLogView({ setModal(type) } + const liveLogGpsPrefillOptions = { + timeoutMs: 8000, + enableHighAccuracy: false, + maximumAge: 60_000 + } as const + const openSogModal = async () => { let prefill = '' try { const permission = await queryGeolocationPermission() if (permission === 'granted') { - const pos = await getCurrentPosition({ - timeoutMs: 8000, - enableHighAccuracy: false, - maximumAge: 60_000 - }) + const pos = await getCurrentPosition(liveLogGpsPrefillOptions) if (pos.speedKn != null) prefill = String(pos.speedKn) } } catch { @@ -651,6 +654,20 @@ export default function LiveLogView({ openValueModal('sog', prefill) } + const openCourseModal = async () => { + let prefill = lastCourseFromEvents(events) + try { + const permission = await queryGeolocationPermission() + if (permission === 'granted') { + const pos = await getCurrentPosition(liveLogGpsPrefillOptions) + if (pos.headingDeg != null) prefill = formatCourseAngle(pos.headingDeg, true) + } + } catch { + // Fall back to last logged course or manual entry + } + openValueModal('course', prefill) + } + const handleMotorToggle = () => { hapticPulse() const starting = !motorRunning @@ -1433,7 +1450,7 @@ export default function LiveLogView({ onCastOff={handleCastOff} onMoor={handleMoor} onOpenSails={() => { setSelectedSails([]); setModal('sails') }} - onOpenCourse={() => openValueModal('course', lastCourseFromEvents(events))} + onOpenCourse={() => void openCourseModal()} onOpenSog={() => void openSogModal()} onOpenStw={() => openValueModal('stw')} onOpenFuel={() => openValueModal('fuel')} @@ -1796,6 +1813,7 @@ export default function LiveLogView({
{t('logs.live_course_hint')}