mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user