Centralize waypoint Yjs serialization in waypointFromYMap/waypointToYMap

Introduce waypoint-ymap.ts with typed helpers so all Yjs↔Waypoint
conversions go through one place. New Waypoint fields now only need
to be added once rather than in every consumer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-05-18 21:02:27 +02:00
parent 02f8a8be44
commit 9e2ca5595e
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
8 changed files with 63 additions and 52 deletions

View file

@ -4,7 +4,7 @@ import * as Y from "yjs";
import type { YjsState } from "~/lib/use-yjs";
import { generateGpx, computeDays } from "@trails-cool/gpx";
import type { TrackPoint, NoGoArea } from "@trails-cool/gpx";
import type { WaypointPoiTags } from "@trails-cool/types";
import { waypointFromYMap } from "~/lib/waypoint-ymap";
function getTracks(yjs: YjsState): TrackPoint[][] {
const geojsonStr = yjs.routeData.get("geojson") as string | undefined;
@ -20,15 +20,7 @@ function getTracks(yjs: YjsState): TrackPoint[][] {
}
function getWaypoints(yjs: YjsState) {
return yjs.waypoints.toArray().map((yMap: Y.Map<unknown>) => ({
lat: yMap.get("lat") as number,
lon: yMap.get("lon") as number,
name: yMap.get("name") as string | undefined,
isDayBreak: yMap.get("overnight") === true ? true : undefined,
note: yMap.get("note") as string | undefined,
osmId: yMap.get("osmId") as number | undefined,
poiTags: yMap.get("poiTags") as WaypointPoiTags | undefined,
}));
return yjs.waypoints.toArray().map(waypointFromYMap);
}
function getNoGoAreas(yjs: YjsState): NoGoArea[] {