Guard optional event fields before calling trim in live-log paths.
Legacy decrypted events may omit mgk or wind fields; optional chaining prevents runtime crashes in course prefill and stats aggregation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -81,14 +81,16 @@ function hapticPulse() {
|
||||
|
||||
function lastCourseFromEvents(events: LogEventPayload[]): string {
|
||||
for (let i = events.length - 1; i >= 0; i--) {
|
||||
if (events[i].mgk.trim()) return events[i].mgk
|
||||
const mgk = events[i].mgk?.trim()
|
||||
if (mgk) return mgk
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function lastWindDirectionFromEvents(events: LogEventPayload[]): string {
|
||||
for (let i = events.length - 1; i >= 0; i--) {
|
||||
if (events[i].windDirection.trim()) return events[i].windDirection
|
||||
const direction = events[i].windDirection?.trim()
|
||||
if (direction) return direction
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -71,21 +71,21 @@ export async function loadLogbookEventSeries(logbookId: string): Promise<EventSe
|
||||
time: event.time
|
||||
}
|
||||
|
||||
if (event.windPressure.trim()) {
|
||||
if (event.windPressure?.trim()) {
|
||||
pressure.push({
|
||||
...base,
|
||||
summary: `${event.windPressure} hPa`
|
||||
})
|
||||
}
|
||||
|
||||
if (event.windDirection.trim() || event.windStrength.trim()) {
|
||||
if (event.windDirection?.trim() || event.windStrength?.trim()) {
|
||||
wind.push({
|
||||
...base,
|
||||
summary: [event.windDirection, event.windStrength].filter(Boolean).join(' ')
|
||||
})
|
||||
}
|
||||
|
||||
const code = event.remarks.trim()
|
||||
const code = event.remarks?.trim() ?? ''
|
||||
if (
|
||||
code === LIVE_EVENT_CODES.MOTOR_START ||
|
||||
code === LIVE_EVENT_CODES.MOTOR_STOP
|
||||
|
||||
Reference in New Issue
Block a user