trails/apps/planner/app/lib/overnight.ts
Ullrich Schäfer efdb3c1973
Add multi-day data model, computeDays, and GPX roundtrip
- overnight.ts: Yjs helpers to set/clear/check overnight flag on waypoints
- compute-days.ts: Pure function splitting routes into DayStage[] at day breaks
- use-days.ts: Reactive hook mapping Yjs state into computeDays() input
- GPX generate: emit <type>overnight</type> for isDayBreak waypoints
- GPX parse: recognize <type>overnight</type> and set isDayBreak on waypoints

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 23:51:31 +02:00

24 lines
621 B
TypeScript

import * as Y from "yjs";
import type { YjsState } from "./use-yjs.ts";
/**
* Set or clear the overnight flag on a waypoint.
*/
export function setOvernight(yjs: YjsState, index: number, value: boolean): void {
const waypointMap = yjs.waypoints.get(index);
if (!waypointMap) return;
yjs.doc.transact(() => {
if (value) {
waypointMap.set("overnight", true);
} else {
waypointMap.delete("overnight");
}
}, "local");
}
/**
* Check if a waypoint Y.Map has the overnight flag set.
*/
export function isOvernight(yMap: Y.Map<unknown>): boolean {
return yMap.get("overnight") === true;
}