fix(planner): a place added from a collection keeps its category (#3074)

The place form guessed the category of a picked place from its kind, so a
place taken from a collection inside a trip lost the category it was saved
under, while adding it from the collection kept it. A picked place that
carries a category this server has now brings it along; a category chosen
in the form by hand still wins.
This commit is contained in:
Maurice
2026-11-12 23:06:35 +01:00
parent f13a0aa6ee
commit a39f3fe40c
3 changed files with 49 additions and 1 deletions
@@ -410,3 +410,15 @@ export function formPin(form: Pick<PlaceFormData, 'lat' | 'lng'>): { lat: number
if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180) return null
return { lat, lng }
}
/**
* The category a picked place already carries, as the form's value, when this server
* has it. A place saved in a collection keeps its category_id, and categories are the
* server's own, so it fits the trip as it stands. Guessing from the place's kind
* instead dropped it (#3074).
*/
export function savedCategoryId(result: Record<string, unknown>, categories: readonly { id: number }[]): string | null {
const id = result.category_id
if (typeof id !== 'number') return null
return categories.some(c => c.id === id) ? String(id) : null
}